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);
}
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);
}
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;
}
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;
}
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);
}
Aggregations