Search in sources :

Example 1 with InnerType

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();
}
Also used : InnerType(io.ordinate.engine.schema.InnerType)

Example 2 with InnerType

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;
}
Also used : SqlTypeName(org.apache.calcite.sql.type.SqlTypeName) InnerType(io.ordinate.engine.schema.InnerType) RelCollation(org.apache.calcite.rel.RelCollation) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) RelFieldCollation(org.apache.calcite.rel.RelFieldCollation)

Example 3 with InnerType

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;
}
Also used : SessionVariableFunction(io.ordinate.engine.function.bind.SessionVariableFunction) ExtractFunction(io.mycat.calcite.sqlfunction.datefunction.ExtractFunction) VariableParameterFunction(io.ordinate.engine.function.bind.VariableParameterFunction) StringFunction(io.ordinate.engine.function.StringFunction) Function(io.ordinate.engine.function.Function) IndexedParameterLinkFunction(io.ordinate.engine.function.bind.IndexedParameterLinkFunction) SessionVariableFunction(io.ordinate.engine.function.bind.SessionVariableFunction) StringFunction(io.ordinate.engine.function.StringFunction) InnerType(io.ordinate.engine.schema.InnerType) NlsString(org.apache.calcite.util.NlsString) SessionVariable(io.ordinate.engine.function.bind.SessionVariable) SqlKind(org.apache.calcite.sql.SqlKind)

Example 4 with InnerType

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;
}
Also used : RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) InnerType(io.ordinate.engine.schema.InnerType)

Example 5 with InnerType

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);
}
Also used : ArrayList(java.util.ArrayList) InnerType(io.ordinate.engine.schema.InnerType) IntInnerType(io.ordinate.engine.schema.IntInnerType) IntInnerType(io.ordinate.engine.schema.IntInnerType)

Aggregations

InnerType (io.ordinate.engine.schema.InnerType)23 IntInnerType (io.ordinate.engine.schema.IntInnerType)10 Schema (org.apache.arrow.vector.types.pojo.Schema)6 Field (org.apache.arrow.vector.types.pojo.Field)5 Function (io.ordinate.engine.function.Function)4 ImmutableList (com.google.common.collect.ImmutableList)3 AccumulatorFunction (io.ordinate.engine.function.aggregate.AccumulatorFunction)3 Map (io.questdb.cairo.map.Map)3 MapKey (io.questdb.cairo.map.MapKey)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 VectorSchemaRoot (org.apache.arrow.vector.VectorSchemaRoot)3 GroupKeys (io.ordinate.engine.builder.GroupKeys)2 VariableParameterFunction (io.ordinate.engine.function.bind.VariableParameterFunction)2 MapFactory (io.ordinate.engine.structure.MapFactory)2 SimpleMapValue (io.questdb.griffin.engine.groupby.SimpleMapValue)2 Observable (io.reactivex.rxjava3.core.Observable)2 Function (io.reactivex.rxjava3.functions.Function)2 Collections (java.util.Collections)2 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)2