use of io.ordinate.engine.schema.InnerType in project Mycat2 by MyCATApache.
the class ExecuteCompiler method cast.
public static Function cast(Function argExpr, InnerType targetArrowType) {
InnerType type = argExpr.getType();
if (type.equals(targetArrowType)) {
return argExpr;
}
List<FunctionFactoryDescriptor> cast = functionFactoryCache.getListByName("cast");
for (FunctionFactoryDescriptor functionFactoryDescriptor : cast) {
List<InnerType> argTypes = functionFactoryDescriptor.getArgTypes();
if (argTypes.get(0).equals(type)) {
if (targetArrowType.equals(functionFactoryDescriptor.getType())) {
return functionFactoryDescriptor.getFactory().newInstance(Collections.singletonList(argExpr));
}
}
}
throw new UnsupportedOperationException();
}
use of io.ordinate.engine.schema.InnerType in project Mycat2 by MyCATApache.
the class CalciteCompiler method getPhysicalSortProperties.
public static List<PhysicalSortProperty> getPhysicalSortProperties(Sort sort) {
RelCollation collation = sort.collation;
List<PhysicalSortProperty> physicalSortProperties = new ArrayList<>();
List<RelDataTypeField> fieldList = sort.getRowType().getFieldList();
for (RelFieldCollation fieldCollation : collation.getFieldCollations()) {
int fieldIndex = fieldCollation.getFieldIndex();
RelFieldCollation.Direction direction = fieldCollation.direction;
SortOptions sortOptions = new SortOptions();
switch(direction) {
case ASCENDING:
sortOptions.descending = false;
break;
case DESCENDING:
sortOptions.descending = true;
break;
case STRICTLY_ASCENDING:
case STRICTLY_DESCENDING:
case CLUSTERED:
throw new UnsupportedOperationException();
}
switch(fieldCollation.nullDirection) {
case FIRST:
sortOptions.nullsFirst = true;
break;
case LAST:
case UNSPECIFIED:
sortOptions.nullsFirst = false;
break;
}
SqlTypeName sqlTypeName = fieldList.get(fieldIndex).getType().getSqlTypeName();
InnerType innerType = RexConverter.convertColumnType(sqlTypeName);
physicalSortProperties.add(PhysicalSortProperty.of(fieldIndex, sortOptions, innerType));
}
return physicalSortProperties;
}
use of io.ordinate.engine.schema.InnerType in project Mycat2 by MyCATApache.
the class RexConverter method convertToFunction.
public Function convertToFunction(RexCall call, List<Function> aeOperands) {
final Function ae;
SqlKind kind = call.op.kind;
String lowerName = kind.lowerName;
switch(call.op.kind) {
// Conjunction
case AND:
ae = executeCompiler.call(lowerName, aeOperands);
break;
case OR:
if (aeOperands.size() == 2) {
// Binary OR
ae = executeCompiler.call(lowerName, aeOperands);
} else {
// COMPARE_IN
ae = executeCompiler.call("in", aeOperands);
}
break;
// Binary Comparison
case EQUALS:
ae = executeCompiler.call("=", aeOperands);
break;
case NOT_EQUALS:
ae = executeCompiler.call("!=", aeOperands);
break;
case LESS_THAN:
ae = executeCompiler.call("<", aeOperands);
break;
case GREATER_THAN:
ae = executeCompiler.call(">", aeOperands);
break;
case LESS_THAN_OR_EQUAL:
ae = executeCompiler.call("<=", aeOperands);
break;
case GREATER_THAN_OR_EQUAL:
ae = executeCompiler.call(">=", aeOperands);
break;
case LIKE:
ae = executeCompiler.call("like", aeOperands);
break;
// Arthimetic Operators
case PLUS:
// todo datetime
ae = executeCompiler.call("+", aeOperands);
break;
case MINUS:
// todo datetime
// Check for DATETIME - INTERVAL expression first
// For whatever reason Calcite treats + and - DATETIME operation differently
ae = executeCompiler.call("-", aeOperands);
break;
case TIMES:
ae = executeCompiler.call("*", aeOperands);
break;
case DIVIDE:
ae = executeCompiler.call("/", aeOperands);
break;
case CAST:
InnerType targetType = convertColumnType(call.getType());
ae = executeCompiler.cast(aeOperands.get(0), targetType);
break;
case NOT:
ae = executeCompiler.call("not", aeOperands.get(0));
break;
case IS_NULL:
ae = executeCompiler.call("isNull", aeOperands.get(0));
break;
case IS_NOT_NULL:
ae = executeCompiler.call("isNotNull", aeOperands.get(0));
break;
case EXISTS:
ae = executeCompiler.call("exists", aeOperands.get(0));
break;
case CASE:
ae = executeCompiler.call("case", aeOperands);
break;
case COALESCE:
ae = executeCompiler.call("coalesce", aeOperands);
break;
case OTHER:
case OTHER_FUNCTION:
default:
String callName = call.op.getName().toUpperCase();
if (callName.contains("SESSIONVALUE")) {
Function function = aeOperands.get(0);
StringFunction stringFunction = (StringFunction) function;
String name = stringFunction.getString(null).toString();
SessionVariableFunction sessionVariableFunction = ExecuteCompiler.newSessionVariable(name);
sessionVariableFunctionMap.add(sessionVariableFunction);
ae = sessionVariableFunction;
} else {
ae = executeCompiler.call(callName, aeOperands);
if (ae == null) {
throw new IllegalArgumentException("Unsupported Calcite expression type! " + call.op.kind.toString());
}
if (ae instanceof SessionVariable) {
sessionVariableFunctionMap.add((SessionVariable) ae);
}
}
}
Objects.requireNonNull(ae);
return ae;
}
use of io.ordinate.engine.schema.InnerType in project Mycat2 by MyCATApache.
the class RexConverter method convertColumnTypeList.
public static List<InnerType> convertColumnTypeList(RelDataType type) {
ArrayList<InnerType> objects = new ArrayList<>();
for (RelDataTypeField relDataTypeField : type.getFieldList()) {
InnerType innerType = convertColumnType(relDataTypeField.getType().getSqlTypeName());
objects.add(innerType);
}
return objects;
}
use of io.ordinate.engine.schema.InnerType in project Mycat2 by MyCATApache.
the class CodeGenRecordSinkFactoryImpl method generateCopyRecordToVectorBatchBody.
private static BlockStatement generateCopyRecordToVectorBatchBody(IntInnerType[] types) {
int size = types.length;
ArrayList<Statement> statements = new ArrayList<>(size);
for (int varIndex = 0; varIndex < size; varIndex++) {
IntInnerType intPair = types[varIndex];
int columnIndex = intPair.index;
InnerType type = intPair.type;
ConstantExpression index = Expressions.constant(columnIndex);
ParameterExpression vectorVariable = Expressions.parameter(type.getFieldVector());
statements.add(Expressions.declare(0, vectorVariable, Expressions.convert_(Expressions.call(input, "getVector", index), type.getFieldVector())));
ParameterExpression returnVariable = Expressions.parameter(type.getJavaClass());
statements.add(Expressions.declare(0, returnVariable, Expressions.call(from, "get" + type.name(), index)));
MethodCallExpression isNullCondition = Expressions.call(from, "isNull", index);
statements.add(Expressions.ifThenElse(isNullCondition, Expressions.statement(Expressions.call(RecordSinkFactoryImpl.class, "set" + type.getFieldVector().getSimpleName() + "Null", vectorVariable, index)), Expressions.statement(Expressions.call(RecordSinkFactoryImpl.class, "set" + type.getFieldVector().getSimpleName(), vectorVariable, rowId, returnVariable))));
}
return Expressions.block(statements);
}
Aggregations