/** Returns the expression to access a table within a schema. */ public static Expression tableExpression( Schema schema, Type elementType, String tableName, Class clazz) { final MethodCallExpression expression; if (Table.class.isAssignableFrom(clazz)) { expression = Expressions.call( schema.getExpression(), BuiltinMethod.SCHEMA_GET_TABLE.method, Expressions.constant(tableName)); } else { expression = Expressions.call( BuiltinMethod.SCHEMAS_QUERYABLE.method, DataContext.ROOT, schema.getExpression(), Expressions.constant(elementType), Expressions.constant(tableName)); } return Types.castIfNecessary(clazz, expression); }
/** Returns the expression for a sub-schema. */ public static Expression subSchemaExpression(Schema schema, String name, Class type) { // (Type) schemaExpression.getSubSchema("name") Expression call = Expressions.call( schema.getExpression(), BuiltinMethod.SCHEMA_GET_SUB_SCHEMA.method, Expressions.constant(name)); // CHECKSTYLE: IGNORE 2 //noinspection unchecked if (false && type != null && !type.isAssignableFrom(Schema.class)) { return unwrap(call, type); } return call; }
@Override protected PreparedExecution implement( RelDataType rowType, RelNode rootRel, SqlKind sqlKind, ClassDeclaration decl, Argument[] args) { RelDataType resultType = rootRel.getRowType(); boolean isDml = sqlKind.belongsTo(SqlKind.DML); javaCompiler = createCompiler(); EnumerableRelImplementor relImplementor = getRelImplementor(rootRel.getCluster().getRexBuilder()); BlockExpression expr = relImplementor.implementRoot((EnumerableRel) rootRel); ParameterExpression root0 = Expressions.parameter(DataContext.class, "root0"); String s = Expressions.toString( Blocks.create( Expressions.declare( Modifier.FINAL, (ParameterExpression) schema.getExpression(), root0), expr), false); final Executable executable; try { executable = (Executable) ExpressionEvaluator.createFastScriptEvaluator( s, Executable.class, new String[] {root0.name}); } catch (Exception e) { throw Helper.INSTANCE.wrap("Error while compiling generated Java code:\n" + s, e); } if (timingTracer != null) { timingTracer.traceTime("end codegen"); } if (timingTracer != null) { timingTracer.traceTime("end compilation"); } return new PreparedExecution( null, rootRel, resultType, isDml, mapTableModOp(isDml, sqlKind), null) { public Object execute() { return executable.execute(schema); } }; }
public Expression getExpression(SchemaPlus parentSchema, String name) { return schema.getExpression(parentSchema, name); }