use of org.apache.calcite.adapter.jdbc.JdbcRel in project calcite by apache.
the class JdbcToSparkConverter method implementSpark.
public SparkRel.Result implementSpark(SparkRel.Implementor implementor) {
// Generate:
// ResultSetEnumerable.of(schema.getDataSource(), "select ...")
final BlockBuilder list = new BlockBuilder();
final JdbcRel child = (JdbcRel) getInput();
final PhysType physType = PhysTypeImpl.of(implementor.getTypeFactory(), getRowType(), JavaRowFormat.CUSTOM);
final JdbcConvention jdbcConvention = (JdbcConvention) child.getConvention();
String sql = generateSql(jdbcConvention.dialect);
if (CalcitePrepareImpl.DEBUG) {
System.out.println("[" + sql + "]");
}
final Expression sqlLiteral = list.append("sql", Expressions.constant(sql));
final List<Primitive> primitives = new ArrayList<Primitive>();
for (int i = 0; i < getRowType().getFieldCount(); i++) {
final Primitive primitive = Primitive.ofBoxOr(physType.fieldClass(i));
primitives.add(primitive != null ? primitive : Primitive.OTHER);
}
final Expression primitivesLiteral = list.append("primitives", Expressions.constant(primitives.toArray(new Primitive[primitives.size()])));
final Expression enumerable = list.append("enumerable", Expressions.call(BuiltInMethod.RESULT_SET_ENUMERABLE_OF.method, Expressions.call(Expressions.convert_(jdbcConvention.expression, JdbcSchema.class), BuiltInMethod.JDBC_SCHEMA_DATA_SOURCE.method), sqlLiteral, primitivesLiteral));
list.add(Expressions.return_(null, enumerable));
return implementor.result(physType, list.toBlock());
}
Aggregations