Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General Druid refactors #16708

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.druid.java.util.common.StringUtils;

import javax.annotation.concurrent.NotThreadSafe;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;

Expand Down Expand Up @@ -130,6 +131,8 @@
@NotThreadSafe
public class DruidException extends RuntimeException
{
public static final String CLASS_NAME_STR = DruidException.class.getName();

/**
* Starts building a "general" DruidException targeting the specified persona.
*
Expand Down Expand Up @@ -467,14 +470,27 @@ public DruidException build(String formatMe, Object... vals)

public DruidException build(Throwable cause, String formatMe, Object... vals)
{
return new DruidException(
final DruidException retVal = new DruidException(
cause,
errorCode,
targetPersona,
category,
StringUtils.nonStrictFormat(formatMe, vals),
deserialized
);

StackTraceElement[] stackTrace = retVal.getStackTrace();
int firstNonDruidExceptionIndex = 0;
while (
firstNonDruidExceptionIndex < stackTrace.length
&& stackTrace[firstNonDruidExceptionIndex].getClassName().startsWith(CLASS_NAME_STR)) {
++firstNonDruidExceptionIndex;
}
if (firstNonDruidExceptionIndex > 0) {
retVal.setStackTrace(Arrays.copyOfRange(stackTrace, firstNonDruidExceptionIndex, stackTrace.length));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this conditional looks odd... its not wrong; but it will only skip the set if it went over the full stacktrace; but when its 0 it still does it...

I guess the intention here is to clip the exception construction process?
could you add a test for this?
with a case which checks what happens if a DruidException is set as a cause for another DruidException

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this to if (firstNonDruidExceptionIndex > 0)

If firstNonDruidExceptionIndex == stackTrace.length, we should copy an empty array, which is what would happen, and if the the exception is 0, we should not need a copy.

}

return retVal;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.druid.error;

/**
* A failure class that is used to indicate that something is just not implemented yet. This is useful when a
* developer builds something and they intentionally do not implement a specific branch of code or type of object.
* <p>
* The lack of implementation is not necessarily a statement that it SHOULDN'T be implemented, it's just an indication
* that it has not YET been implemented. When one of these exceptions is seen, it is usually an indication that it is
* now time to actually implement the path that was previously elided.
* <p>
* Oftentimes, the code path wasn't implemented because the developer thought that it wasn't actually possible to
* see it executed. So, collecting and providing information about why the particular path got executed is often
* extremely helpful in understanding why it happened and accelerating the implementation of what the correct behavior
* should be.
*/
public class NotYetImplemented extends DruidException.Failure
{
public static DruidException ex(Throwable t, String msg, Object... args)
{
return DruidException.fromFailure(new NotYetImplemented(t, msg, args));
}

private final Throwable t;
private final String msg;
private final Object[] args;

public NotYetImplemented(Throwable t, String msg, Object[] args)
{
super("notYetImplemented");
this.t = t;
this.msg = msg;
this.args = args;
}


@Override
protected DruidException makeException(DruidException.DruidExceptionBuilder bob)
{
bob = bob.forPersona(DruidException.Persona.DEVELOPER)
.ofCategory(DruidException.Category.DEFENSIVE);

if (t == null) {
return bob.build(msg, args);
} else {
return bob.build(t, msg, args);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.apache.druid.frame.read;

import com.google.common.base.Preconditions;
import org.apache.druid.error.DruidException;
import org.apache.druid.frame.Frame;
import org.apache.druid.frame.field.FieldReader;
import org.apache.druid.frame.field.FieldReaders;
Expand All @@ -31,7 +32,6 @@
import org.apache.druid.frame.segment.row.FrameCursorFactory;
import org.apache.druid.frame.write.FrameWriterUtils;
import org.apache.druid.java.util.common.IAE;
import org.apache.druid.java.util.common.ISE;
import org.apache.druid.segment.CursorFactory;
import org.apache.druid.segment.column.ColumnCapabilities;
import org.apache.druid.segment.column.ColumnType;
Expand All @@ -44,7 +44,7 @@

/**
* Embeds the logic to read frames with a given {@link RowSignature}.
*
* <p>
* Stateless and immutable.
*/
public class FrameReader
Expand Down Expand Up @@ -146,7 +146,7 @@ public CursorFactory makeCursorFactory(final Frame frame)
case ROW_BASED:
return new FrameCursorFactory(frame, this, fieldReaders);
default:
throw new ISE("Unrecognized frame type [%s]", frame.type());
throw DruidException.defensive("Unrecognized frame type [%s]", frame.type());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ private static void hieraricalPutValue(
// to configure ParametrizedUriEmitterConfig object. So skipping xxx=yyy key-value pair when configuring Emitter
// doesn't make any difference. That is why we just log this situation, instead of throwing an exception.
log.info(
"Skipping %s property: one of it's prefixes is also used as a property key. Prefix: %s",
"Skipping property [%s]: one of it's prefixes [%s] is also used as a property key.",
originalProperty,
propertyPrefix
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.druid.query.rowsandcols.column.Column;
import org.apache.druid.query.rowsandcols.column.DoubleArrayColumn;
import org.apache.druid.query.rowsandcols.column.IntArrayColumn;
import org.apache.druid.query.rowsandcols.column.LongArrayColumn;
import org.apache.druid.query.rowsandcols.column.ObjectArrayColumn;
import org.apache.druid.query.rowsandcols.semantic.AppendableRowsAndColumns;
import org.apache.druid.segment.column.ColumnType;
Expand Down Expand Up @@ -170,6 +171,12 @@ public Builder add(String name, int[] vals)
return add(name, new IntArrayColumn(vals));
}

@SuppressWarnings("unused")
public Builder add(String name, long[] vals)
{
return add(name, new LongArrayColumn(vals));
}

public Builder add(String name, double[] vals)
{
return add(name, new DoubleArrayColumn(vals));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
import org.apache.druid.java.util.common.ISE;
import org.apache.druid.query.rowsandcols.util.FindResult;

/**
* The implementations of this interface will not validate that things are sorted for the binary search, it assumes that
* they must be. As such, behavior are undefined if the column is not actually sorted.
*/
public interface BinarySearchableAccessor extends ColumnAccessor
{
static BinarySearchableAccessor fromColumn(Column col)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package org.apache.druid.query.rowsandcols.column;

import org.apache.druid.java.util.common.ISE;
import org.apache.druid.error.DruidException;
import org.apache.druid.query.rowsandcols.util.FindResult;
import org.apache.druid.segment.column.ColumnType;

Expand Down Expand Up @@ -55,7 +55,13 @@ public <T> T as(Class<? extends T> clazz)
if (VectorCopier.class.equals(clazz)) {
return (T) (VectorCopier) (into, intoStart) -> {
if (Integer.MAX_VALUE - numRows < intoStart) {
throw new ISE("too many rows!!! intoStart[%,d], numRows[%,d] combine to exceed max_int", intoStart, numRows);
throw DruidException.forPersona(DruidException.Persona.USER)
.ofCategory(DruidException.Category.CAPACITY_EXCEEDED)
.build(
"too many rows!!! intoStart[%,d], vals.length[%,d] combine to exceed max_int",
intoStart,
numRows
);
}
Arrays.fill(into, intoStart, intoStart + numRows, obj);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

package org.apache.druid.query.rowsandcols.column;

import org.apache.druid.java.util.common.ISE;
import org.apache.druid.java.util.common.Numbers;
import org.apache.druid.error.DruidException;
import org.apache.druid.error.NotYetImplemented;
import org.apache.druid.query.rowsandcols.util.FindResult;
import org.apache.druid.segment.column.ColumnType;

Expand Down Expand Up @@ -54,11 +54,13 @@ public <T> T as(Class<? extends T> clazz)
if (VectorCopier.class.equals(clazz)) {
return (T) (VectorCopier) (into, intoStart) -> {
if (Integer.MAX_VALUE - vals.length < intoStart) {
throw new ISE(
"too many rows!!! intoStart[%,d], vals.length[%,d] combine to exceed max_int",
intoStart,
vals.length
);
throw DruidException.forPersona(DruidException.Persona.USER)
.ofCategory(DruidException.Category.CAPACITY_EXCEEDED)
.build(
"too many rows!!! intoStart[%,d], vals.length[%,d] combine to exceed max_int",
intoStart,
vals.length
);
}
for (int i = 0; i < vals.length; ++i) {
into[intoStart + i] = vals[i];
Expand Down Expand Up @@ -183,13 +185,13 @@ public FindResult findLong(int startIndex, int endIndex, long val)
@Override
public FindResult findString(int startIndex, int endIndex, String val)
{
return findDouble(startIndex, endIndex, Numbers.tryParseDouble(val, 0));
throw NotYetImplemented.ex(null, "findString is not currently supported for DoubleArrayColumns");
}

@Override
public FindResult findComplex(int startIndex, int endIndex, Object val)
{
return findDouble(startIndex, endIndex, Numbers.tryParseDouble(val, 0));
throw NotYetImplemented.ex(null, "findComplex is not currently supported for DoubleArrayColumns");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

package org.apache.druid.query.rowsandcols.column;

import org.apache.druid.java.util.common.ISE;
import org.apache.druid.java.util.common.Numbers;
import org.apache.druid.error.DruidException;
import org.apache.druid.error.NotYetImplemented;
import org.apache.druid.query.rowsandcols.util.FindResult;
import org.apache.druid.segment.column.ColumnType;

Expand Down Expand Up @@ -54,11 +54,13 @@ public <T> T as(Class<? extends T> clazz)
if (VectorCopier.class.equals(clazz)) {
return (T) (VectorCopier) (into, intoStart) -> {
if (Integer.MAX_VALUE - vals.length < intoStart) {
throw new ISE(
"too many rows!!! intoStart[%,d], vals.length[%,d] combine to exceed max_int",
intoStart,
vals.length
);
throw DruidException.forPersona(DruidException.Persona.USER)
.ofCategory(DruidException.Category.CAPACITY_EXCEEDED)
.build(
"too many rows!!! intoStart[%,d], vals.length[%,d] combine to exceed max_int",
intoStart,
vals.length
);
}
for (int i = 0; i < vals.length; ++i) {
into[intoStart + i] = vals[i];
Expand Down Expand Up @@ -189,13 +191,13 @@ public FindResult findInt(int startIndex, int endIndex, int val)
@Override
public FindResult findString(int startIndex, int endIndex, String val)
{
return findInt(startIndex, endIndex, (int) Numbers.tryParseLong(val, 0));
throw NotYetImplemented.ex(null, "findString is not currently supported for IntArrayColumns");
}

@Override
public FindResult findComplex(int startIndex, int endIndex, Object val)
{
return findDouble(startIndex, endIndex, (int) Numbers.tryParseLong(val, 0));
throw NotYetImplemented.ex(null, "findComplex is not currently supported for IntArrayColumns");
}
}
}
Loading