Skip to content
Merged
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
18 changes: 7 additions & 11 deletions core/src/main/java/org/apache/druid/math/expr/IdentifierExpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@
import org.apache.druid.java.util.common.StringUtils;
import org.apache.druid.math.expr.vector.ExprEvalDoubleVector;
import org.apache.druid.math.expr.vector.ExprEvalLongVector;
import org.apache.druid.math.expr.vector.ExprEvalStringVector;
import org.apache.druid.math.expr.vector.ExprEvalObjectVector;
import org.apache.druid.math.expr.vector.ExprEvalVector;
import org.apache.druid.math.expr.vector.ExprVectorProcessor;

import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.Objects;

/**
Expand Down Expand Up @@ -158,15 +157,12 @@ public ExprVectorProcessor<?> buildVectorized(VectorInputBindingInspector inspec
if (inputType == null) {
// nil column, we can be anything, so be a string because it's the most flexible
// (numbers will be populated with default values in default mode and non-null)
return new IdentifierVectorProcessor<String[]>(ExpressionType.STRING)
return new IdentifierVectorProcessor<Object[]>(ExpressionType.STRING)
{
@Override
public ExprEvalVector<String[]> evalVector(VectorInputBinding bindings)
public ExprEvalVector<Object[]> evalVector(VectorInputBinding bindings)
{
// need to cast to string[] because null columns come out as object[]
return new ExprEvalStringVector(
Arrays.stream(bindings.getObjectVector(binding)).map(x -> (String) x).toArray(String[]::new)
);
return new ExprEvalObjectVector(bindings.getObjectVector(binding));
}
};
}
Expand All @@ -190,12 +186,12 @@ public ExprEvalVector<double[]> evalVector(VectorInputBinding bindings)
}
};
case STRING:
return new IdentifierVectorProcessor<String[]>(inputType)
return new IdentifierVectorProcessor<Object[]>(inputType)
{
@Override
public ExprEvalVector<String[]> evalVector(VectorInputBinding bindings)
public ExprEvalVector<Object[]> evalVector(VectorInputBinding bindings)
{
return new ExprEvalStringVector(bindings.getObjectVector(binding));
return new ExprEvalObjectVector(bindings.getObjectVector(binding));
}
};
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@
import org.apache.druid.math.expr.Expr;
import org.apache.druid.math.expr.ExpressionType;

public final class CastToStringVectorProcessor extends CastToTypeVectorProcessor<String[]>
public final class CastToStringVectorProcessor extends CastToTypeVectorProcessor<Object[]>
{
public CastToStringVectorProcessor(ExprVectorProcessor<?> delegate)
{
super(delegate);
}

@Override
public ExprEvalVector<String[]> evalVector(Expr.VectorInputBinding bindings)
public ExprEvalVector<Object[]> evalVector(Expr.VectorInputBinding bindings)
{
ExprEvalVector<?> result = delegate.evalVector(bindings);
final Object[] objects = result.getObjectVector();
final String[] output = new String[objects.length];
final Object[] output = new String[objects.length];
for (int i = 0; i < objects.length; i++) {
output[i] = Evals.asString(objects[i]);
}
return new ExprEvalStringVector(output);
return new ExprEvalObjectVector(output);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
package org.apache.druid.math.expr.vector;

import org.apache.druid.common.config.NullHandling;
import org.apache.druid.math.expr.Evals;
import org.apache.druid.math.expr.ExprEval;
import org.apache.druid.math.expr.ExpressionType;

import javax.annotation.Nullable;

public final class ExprEvalStringVector extends ExprEvalVector<String[]>
public final class ExprEvalObjectVector extends ExprEvalVector<Object[]>
{
@Nullable
private long[] longs;
Expand All @@ -35,7 +36,7 @@ public final class ExprEvalStringVector extends ExprEvalVector<String[]>
@Nullable
private boolean[] numericNulls;

public ExprEvalStringVector(String[] values)
public ExprEvalObjectVector(Object[] values)
{
super(values, null);
}
Expand All @@ -47,7 +48,7 @@ private void computeNumbers()
doubles = new double[values.length];
numericNulls = new boolean[values.length];
for (int i = 0; i < values.length; i++) {
Number n = ExprEval.computeNumber(values[i]);
Number n = ExprEval.computeNumber(Evals.asString(values[i]));
if (n != null) {
longs[i] = n.longValue();
doubles[i] = n.doubleValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* Result of {@link ExprVectorProcessor#evalVector} which wraps the actual evaluated results of the operation over the
* input vector(s). Methods to get actual results mirror vectorized value and object selectors.
*
* The generic parameter T should be the native java array type of the vector result (long[], String[], etc.)
* The generic parameter T should be the native java array type of the vector result (long[], Object[], etc.)
*/
public abstract class ExprEvalVector<T>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,21 @@
import org.apache.druid.math.expr.ExpressionType;

/**
* specialized {@link UnivariateFunctionVectorObjectProcessor} for processing (String[]) -> long[]
* specialized {@link UnivariateFunctionVectorObjectProcessor} for processing (Object[]) -> long[]
*/
public abstract class LongOutStringInFunctionVectorProcessor
extends UnivariateFunctionVectorObjectProcessor<String[], long[]>
public abstract class LongOutObjectInFunctionVectorProcessor
extends UnivariateFunctionVectorObjectProcessor<Object[], long[]>
{
public LongOutStringInFunctionVectorProcessor(ExprVectorProcessor<String[]> processor, int maxVectorSize)
final ExpressionType inputType;

public LongOutObjectInFunctionVectorProcessor(
ExprVectorProcessor<Object[]> processor,
int maxVectorSize,
ExpressionType inputType
)
{
super(CastToTypeVectorProcessor.cast(processor, ExpressionType.STRING), maxVectorSize, new long[maxVectorSize]);
super(CastToTypeVectorProcessor.cast(processor, inputType), maxVectorSize, new long[maxVectorSize]);
this.inputType = inputType;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,34 @@

import javax.annotation.Nullable;

public abstract class LongOutStringsInFunctionVectorProcessor extends BivariateFunctionVectorObjectProcessor<String[], String[], long[]>
public abstract class LongOutObjectsInFunctionVectorProcessor
extends BivariateFunctionVectorObjectProcessor<Object[], Object[], long[]>
{
private final boolean[] outNulls;

protected LongOutStringsInFunctionVectorProcessor(
ExprVectorProcessor<String[]> left,
ExprVectorProcessor<String[]> right,
int maxVectorSize
protected LongOutObjectsInFunctionVectorProcessor(
ExprVectorProcessor<Object[]> left,
ExprVectorProcessor<Object[]> right,
int maxVectorSize,
ExpressionType inputType
)
{
super(
CastToTypeVectorProcessor.cast(left, ExpressionType.STRING),
CastToTypeVectorProcessor.cast(right, ExpressionType.STRING),
CastToTypeVectorProcessor.cast(left, inputType),
CastToTypeVectorProcessor.cast(right, inputType),
maxVectorSize,
new long[maxVectorSize]
);
this.outNulls = new boolean[maxVectorSize];
}

@Nullable
abstract Long processValue(@Nullable String leftVal, @Nullable String rightVal);
abstract Long processValue(@Nullable Object leftVal, @Nullable Object rightVal);

@Override
void processIndex(String[] strings, String[] strings2, int i)
void processIndex(Object[] in1, Object[] in2, int i)
{
final Long outVal = processValue(strings[i], strings2[i]);
final Long outVal = processValue(in1[i], in2[i]);
if (outVal == null) {
outValues[i] = 0L;
outNulls[i] = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,50 +19,52 @@

package org.apache.druid.math.expr.vector;

import org.apache.druid.common.config.NullHandling;
import org.apache.druid.math.expr.Expr;
import org.apache.druid.math.expr.ExpressionType;

/**
* many strings enter, one string leaves...
*/
public abstract class StringOutMultiStringInVectorProcessor implements ExprVectorProcessor<String[]>
public abstract class ObjectOutMultiObjectInVectorProcessor implements ExprVectorProcessor<Object[]>
{
final ExprVectorProcessor<String[]>[] inputs;
final ExprVectorProcessor<Object[]>[] inputs;
final int maxVectorSize;
final String[] outValues;
final boolean sqlCompatible = NullHandling.sqlCompatible();
final Object[] outValues;

protected StringOutMultiStringInVectorProcessor(
ExprVectorProcessor<String[]>[] inputs,
int maxVectorSize
final ExpressionType expressionType;

protected ObjectOutMultiObjectInVectorProcessor(
ExprVectorProcessor<Object[]>[] inputs,
int maxVectorSize,
ExpressionType objectType
)
{
this.inputs = inputs;
this.maxVectorSize = maxVectorSize;
this.outValues = new String[maxVectorSize];
this.outValues = new Object[maxVectorSize];
this.expressionType = objectType;
}

@Override
public ExpressionType getOutputType()
{
return ExpressionType.STRING;
return expressionType;
}

@Override
public ExprEvalVector<String[]> evalVector(Expr.VectorInputBinding bindings)
public ExprEvalVector<Object[]> evalVector(Expr.VectorInputBinding bindings)
{
final int currentSize = bindings.getCurrentVectorSize();
final String[][] in = new String[inputs.length][];
final Object[][] in = new Object[inputs.length][];
for (int i = 0; i < inputs.length; i++) {
in[i] = inputs[i].evalVector(bindings).values();
}

for (int i = 0; i < currentSize; i++) {
processIndex(in, i);
}
return new ExprEvalStringVector(outValues);
return new ExprEvalObjectVector(outValues);
}

abstract void processIndex(String[][] in, int i);
abstract void processIndex(Object[][] in, int i);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,34 @@

import javax.annotation.Nullable;

public abstract class StringOutStringsInFunctionVectorProcessor
extends BivariateFunctionVectorObjectProcessor<String[], String[], String[]>
public abstract class ObjectOutObjectsInFunctionVectorProcessor
extends BivariateFunctionVectorObjectProcessor<Object[], Object[], Object[]>
{
protected StringOutStringsInFunctionVectorProcessor(
ExprVectorProcessor<String[]> left,
ExprVectorProcessor<String[]> right,
int maxVectorSize
final ExpressionType expressionType;

protected ObjectOutObjectsInFunctionVectorProcessor(
ExprVectorProcessor<Object[]> left,
ExprVectorProcessor<Object[]> right,
int maxVectorSize,
ExpressionType expressionType
)
{
super(
CastToTypeVectorProcessor.cast(left, ExpressionType.STRING),
CastToTypeVectorProcessor.cast(right, ExpressionType.STRING),
CastToTypeVectorProcessor.cast(left, expressionType),
CastToTypeVectorProcessor.cast(right, expressionType),
maxVectorSize,
new String[maxVectorSize]
new Object[maxVectorSize]
);
this.expressionType = expressionType;
}

@Nullable
protected abstract String processValue(@Nullable String leftVal, @Nullable String rightVal);
protected abstract Object processValue(@Nullable Object leftVal, @Nullable Object rightVal);

@Override
void processIndex(String[] strings, String[] strings2, int i)
void processIndex(Object[] in1, Object[] in2, int i)
{
outValues[i] = processValue(strings[i], strings2[i]);
outValues[i] = processValue(in1[i], in2[i]);
}

@Override
Expand All @@ -56,14 +60,14 @@ void processNull(int i)
}

@Override
ExprEvalVector<String[]> asEval()
ExprEvalVector<Object[]> asEval()
{
return new ExprEvalStringVector(outValues);
return new ExprEvalObjectVector(outValues);
}

@Override
public ExpressionType getOutputType()
{
return ExpressionType.STRING;
return expressionType;
}
}
Loading