Search in sources :

Example 1 with Function

use of io.ordinate.engine.function.Function in project Mycat2 by MyCATApache.

the class CalciteCompiler method convertFilter.

public PhysicalPlan convertFilter(Filter filter) {
    PhysicalPlan input = convert(filter.getInput());
    RexNode condition = filter.getCondition();
    Function function = rexConverter.convertRex(condition, input.schema());
    return executeCompiler.filter(input, function);
}
Also used : ColumnFunction(io.ordinate.engine.function.column.ColumnFunction) IntFunction(io.ordinate.engine.function.IntFunction) VariableParameterFunction(io.ordinate.engine.function.bind.VariableParameterFunction) Function(io.ordinate.engine.function.Function) AccumulatorFunction(io.ordinate.engine.function.aggregate.AccumulatorFunction) RexNode(org.apache.calcite.rex.RexNode)

Example 2 with Function

use of io.ordinate.engine.function.Function in project Mycat2 by MyCATApache.

the class CalciteCompiler method convertProject.

public PhysicalPlan convertProject(Project project) {
    PhysicalPlan input = convert(project.getInput());
    List<RexNode> projects = project.getProjects();
    int index = 0;
    Function[] functions = new Function[projects.size()];
    for (RexNode rexNode : projects) {
        Function function = rexConverter.convertRex(rexNode, input.schema());
        functions[index] = function;
        index++;
    }
    return executeCompiler.project(input, functions);
}
Also used : ColumnFunction(io.ordinate.engine.function.column.ColumnFunction) IntFunction(io.ordinate.engine.function.IntFunction) VariableParameterFunction(io.ordinate.engine.function.bind.VariableParameterFunction) Function(io.ordinate.engine.function.Function) AccumulatorFunction(io.ordinate.engine.function.aggregate.AccumulatorFunction) RexNode(org.apache.calcite.rex.RexNode)

Example 3 with Function

use of io.ordinate.engine.function.Function 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 Function

use of io.ordinate.engine.function.Function in project Mycat2 by MyCATApache.

the class SchemaBuilder method of.

public static Schema of(Function[] functions) {
    final Schema schema;
    ArrowType[] arrowTypes = new ArrowType[functions.length];
    int index = 0;
    for (Function function : functions) {
        arrowTypes[index] = function.getType().getArrowType();
        index++;
    }
    schema = SchemaBuilder.ofArrowType(arrowTypes).toArrow();
    return schema;
}
Also used : Function(io.ordinate.engine.function.Function) Schema(org.apache.arrow.vector.types.pojo.Schema) ArrowType(org.apache.arrow.vector.types.pojo.ArrowType)

Example 5 with Function

use of io.ordinate.engine.function.Function in project Mycat2 by MyCATApache.

the class CsvScanTest method baseTest.

// @Test
@SneakyThrows
public void baseTest() {
    Path path = Paths.get("D:\\testcsv.csv");
    // 
    // CsvWriter writer = new CsvWriter(path.toFile(), new CsvWriterSettings());
    // for (int i = 0; i < 800_0000; i++) {
    // writer.writeRow(Arrays.asList(i,i));
    // }
    // writer.close();
    StopWatch stopWatch = new StopWatch();
    ExecuteCompiler executeCompiler = new ExecuteCompiler();
    CsvScanPlan csvScan = new ValuesCsvScanPlan(path.toString(), SchemaBuilder.ofArrowType(ArrowTypes.INT64_TYPE, ArrowTypes.STRING_TYPE).toArrow(), executeCompiler.createRootContext());
    Function column = executeCompiler.column(0, csvScan.schema());
    Function add = executeCompiler.call("+", Arrays.asList(column, column));
    RootContext rootContext = executeCompiler.createRootContext();
    PhysicalPlan projection = executeCompiler.project(csvScan, Arrays.asList(add));
    for (int i = 0; i < 100; i++) {
        stopWatch.reset();
        stopWatch.start();
        Observable<VectorSchemaRoot> execute = projection.execute(rootContext);
        AtomicLong count = new AtomicLong(0);
        execute.blockingLatest().forEach(c -> {
            count.getAndAdd(c.getRowCount());
            c.close();
        });
        stopWatch.stop();
        System.out.println("count:" + count);
        Duration duration = Duration.ofMillis(stopWatch.getTime());
        System.out.println(duration.getSeconds());
        System.out.println(stopWatch.toString());
    }
// 
// Thread.sleep(100000000);
}
Also used : Path(java.nio.file.Path) ValuesCsvScanPlan(io.ordinate.engine.physicalplan.ValuesCsvScanPlan) VectorSchemaRoot(org.apache.arrow.vector.VectorSchemaRoot) PhysicalPlan(io.ordinate.engine.physicalplan.PhysicalPlan) ValuesCsvScanPlan(io.ordinate.engine.physicalplan.ValuesCsvScanPlan) CsvScanPlan(io.ordinate.engine.physicalplan.CsvScanPlan) Duration(java.time.Duration) StopWatch(org.apache.commons.lang3.time.StopWatch) RootContext(io.ordinate.engine.record.RootContext) Function(io.ordinate.engine.function.Function) AtomicLong(java.util.concurrent.atomic.AtomicLong) ExecuteCompiler(io.ordinate.engine.builder.ExecuteCompiler) SneakyThrows(lombok.SneakyThrows)

Aggregations

Function (io.ordinate.engine.function.Function)15 VariableParameterFunction (io.ordinate.engine.function.bind.VariableParameterFunction)5 ImmutableList (com.google.common.collect.ImmutableList)4 IntFunction (io.ordinate.engine.function.IntFunction)4 AccumulatorFunction (io.ordinate.engine.function.aggregate.AccumulatorFunction)4 ColumnFunction (io.ordinate.engine.function.column.ColumnFunction)4 InnerType (io.ordinate.engine.schema.InnerType)4 Schema (org.apache.arrow.vector.types.pojo.Schema)4 BinarySequence (io.ordinate.engine.function.BinarySequence)3 RexNode (org.apache.calcite.rex.RexNode)3 MycatRelDataType (io.mycat.beans.mycat.MycatRelDataType)2 PhysicalPlan (io.ordinate.engine.physicalplan.PhysicalPlan)2 Record (io.ordinate.engine.record.Record)2 RootContext (io.ordinate.engine.record.RootContext)2 List (java.util.List)2 SneakyThrows (lombok.SneakyThrows)2 VectorSchemaRoot (org.apache.arrow.vector.VectorSchemaRoot)2 JoinType (org.apache.calcite.linq4j.JoinType)2 RelDataType (org.apache.calcite.rel.type.RelDataType)2 RexLiteral (org.apache.calcite.rex.RexLiteral)2