org.apache.calcite.adapter.enumerable.RexImpTable Java Examples
The following examples show how to use
org.apache.calcite.adapter.enumerable.RexImpTable.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SamzaSqlScalarFunctionImpl.java From samza with Apache License 2.0 | 6 votes |
@Override public CallImplementor getImplementor() { return RexImpTable.createImplementor((translator, call, translatedOperands) -> { final Expression sqlContext = Expressions.parameter(SamzaSqlExecutionContext.class, "sqlContext"); final Expression samzaContext = Expressions.parameter(SamzaSqlExecutionContext.class, "context"); final Expression getUdfInstance = Expressions.call(ScalarUdf.class, sqlContext, getUdfMethod, Expressions.constant(udfMethod.getDeclaringClass().getName()), Expressions.constant(udfName), samzaContext); List<Expression> convertedOperands = new ArrayList<>(); // SAMZA: 2230 To allow UDFS to accept Untyped arguments. // We explicitly Convert the untyped arguments to type that the UDf expects. for (int index = 0; index < translatedOperands.size(); index++) { if (!udfMetadata.isDisableArgCheck() && translatedOperands.get(index).type == Object.class && udfMethod.getParameters()[index].getType() != Object.class) { convertedOperands.add(Expressions.convert_(translatedOperands.get(index), udfMethod.getParameters()[index].getType())); } else { convertedOperands.add(translatedOperands.get(index)); } } final Expression callExpression = Expressions.call(Expressions.convert_(getUdfInstance, udfMethod.getDeclaringClass()), udfMethod, convertedOperands); return callExpression; }, NullPolicy.NONE, false); }
Example #2
Source File: TableFunctionImpl.java From calcite with Apache License 2.0 | 6 votes |
private static CallImplementor createImplementor(final Method method) { return RexImpTable.createImplementor( new ReflectiveCallNotNullImplementor(method) { public Expression implement(RexToLixTranslator translator, RexCall call, List<Expression> translatedOperands) { Expression expr = super.implement(translator, call, translatedOperands); final Class<?> returnType = method.getReturnType(); if (QueryableTable.class.isAssignableFrom(returnType)) { Expression queryable = Expressions.call( Expressions.convert_(expr, QueryableTable.class), BuiltInMethod.QUERYABLE_TABLE_AS_QUERYABLE.method, Expressions.call(DataContext.ROOT, BuiltInMethod.DATA_CONTEXT_GET_QUERY_PROVIDER.method), Expressions.constant(null, SchemaPlus.class), Expressions.constant(call.getOperator().getName(), String.class)); expr = Expressions.call(queryable, BuiltInMethod.QUERYABLE_AS_ENUMERABLE.method); } else { expr = Expressions.call(expr, BuiltInMethod.SCANNABLE_TABLE_SCAN.method, DataContext.ROOT); } return expr; } }, NullPolicy.NONE, false); }
Example #3
Source File: HiveSqlOperatorTable.java From marble with Apache License 2.0 | 5 votes |
private void defineImplementors() { //define implementors for hive operators final List<SqlOperator> operatorList = getOperatorList(); RexImpTable.INSTANCE.defineImplementors((map, aggMap, winAggMap) -> { for (SqlOperator sqlOperator : operatorList) { if (sqlOperator instanceof HiveSqlAggFunction) { HiveSqlAggFunction aggFunction = (HiveSqlAggFunction) sqlOperator; aggMap.put(aggFunction, () -> new HiveUDAFImplementor(aggFunction)); } else { /**since SqlOperator is identified by name and kind ,see * {@link SqlOperator#equals(Object)} and * {@link SqlOperator#hashCode()}, * we can override implementors of operators that declared in * SqlStdOperatorTable * */ CallImplementor callImplementor; if (sqlOperator.getName().equals("NOT RLIKE") || sqlOperator.getName() .equals("NOT REGEXP")) { callImplementor = RexImpTable.createImplementor( RexImpTable.NotImplementor.of( new HiveUDFImplementor()), NullPolicy.STRICT, false); } else { callImplementor = RexImpTable.createImplementor( new HiveUDFImplementor(), NullPolicy.NONE, false); } map.put(sqlOperator, callImplementor); } } // directly override some implementors of SqlOperator that declared in // SqlStdOperatorTable map.put(SqlStdOperatorTable.ITEM, new RexImpTable.ItemImplementor(true)); }); }
Example #4
Source File: ElasticsearchRules.java From calcite with Apache License 2.0 | 5 votes |
@Override public String visitLiteral(RexLiteral literal) { if (literal.getValue() == null) { return "null"; } return "\"literal\":\"" + RexToLixTranslator.translateLiteral(literal, literal.getType(), typeFactory, RexImpTable.NullAs.NOT_POSSIBLE) + "\""; }
Example #5
Source File: MongoRules.java From calcite with Apache License 2.0 | 5 votes |
@Override public String visitLiteral(RexLiteral literal) { if (literal.getValue() == null) { return "null"; } return "{$literal: " + RexToLixTranslator.translateLiteral(literal, literal.getType(), typeFactory, RexImpTable.NullAs.NOT_POSSIBLE) + "}"; }
Example #6
Source File: CollectionsFunctions.java From mat-calcite-plugin with Apache License 2.0 | 4 votes |
BaseImplementableFunction(Method method) { super(method); implementor = RexImpTable.createImplementor(new ReflectiveCallNotNullImplementor(method), NullPolicy.NONE, false); }
Example #7
Source File: SparkRules.java From calcite with Apache License 2.0 | 4 votes |
public Result implementSpark(Implementor implementor) { /* return Linq4j.asSpark( new Object[][] { new Object[] {1, 2}, new Object[] {3, 4} }); */ final JavaTypeFactory typeFactory = (JavaTypeFactory) getCluster().getTypeFactory(); final BlockBuilder builder = new BlockBuilder(); final PhysType physType = PhysTypeImpl.of(implementor.getTypeFactory(), getRowType(), JavaRowFormat.CUSTOM); final Type rowClass = physType.getJavaRowType(); final List<Expression> expressions = new ArrayList<>(); final List<RelDataTypeField> fields = rowType.getFieldList(); for (List<RexLiteral> tuple : tuples) { final List<Expression> literals = new ArrayList<>(); for (Pair<RelDataTypeField, RexLiteral> pair : Pair.zip(fields, tuple)) { literals.add( RexToLixTranslator.translateLiteral( pair.right, pair.left.getType(), typeFactory, RexImpTable.NullAs.NULL)); } expressions.add(physType.record(literals)); } builder.add( Expressions.return_(null, Expressions.call(SparkMethod.ARRAY_TO_RDD.method, Expressions.call(SparkMethod.GET_SPARK_CONTEXT.method, implementor.getRootExpression()), Expressions.newArrayInit(Primitive.box(rowClass), expressions)))); return implementor.result(physType, builder.toBlock()); }
Example #8
Source File: AggregateFunctionImpl.java From calcite with Apache License 2.0 | 4 votes |
public AggImplementor getImplementor(boolean windowContext) { return new RexImpTable.UserDefinedAggReflectiveImplementor(this); }
Example #9
Source File: ScalarFunctionImpl.java From calcite with Apache License 2.0 | 4 votes |
private static CallImplementor createImplementor(final Method method) { final NullPolicy nullPolicy = getNullPolicy(method); return RexImpTable.createImplementor( new ReflectiveCallNotNullImplementor(method), nullPolicy, false); }