@Override @SuppressWarnings("rawtypes") public Expression getExpression(final SchemaPlus schema, final String tableName, final Class clazz) { return Schemas.tableExpression(schema, getElementType(), tableName, clazz); }
/** Creates a path with a given list of names starting from a given root * schema. */ public static Path path(CalciteSchema rootSchema, Iterable<String> names) { final ImmutableList.Builder<Pair<String, Schema>> builder = ImmutableList.builder(); Schema schema = rootSchema.plus(); final Iterator<String> iterator = names.iterator(); if (!iterator.hasNext()) { return PathImpl.EMPTY; } if (!rootSchema.name.isEmpty()) { Preconditions.checkState(rootSchema.name.equals(iterator.next())); } for (;;) { final String name = iterator.next(); builder.add(Pair.of(name, schema)); if (!iterator.hasNext()) { return path(builder.build()); } schema = schema.getSubSchema(name); } }
@Override protected List<LatticeEntry> getLattices() { return Schemas.getLatticeEntries(schema); } }
public Iterator<Object> iterator() { final DataContext dataContext = Schemas.createDataContext(connection, calciteSignature.rootSchema.plus()); return calciteSignature.enumerable(dataContext).iterator(); } });
@Test public void testTableWhere() throws SQLException, ClassNotFoundException { final Connection connection = CalciteAssert.that(CalciteAssert.Config.JDBC_FOODMART).connect(); final CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class); final SchemaPlus rootSchema = calciteConnection.getRootSchema(); ParameterExpression c = Expressions.parameter(JdbcTest.Customer.class, "c"); String s = Schemas.queryable(Schemas.createDataContext(connection, rootSchema), rootSchema.getSubSchema("foodmart"), JdbcTest.Customer.class, "customer") .where( Expressions.lambda( Expressions.lessThan( Expressions.field(c, "customer_id"), Expressions.constant(5)), c)) .toList() .toString(); Util.discard(s); } }
/** * Creates a context for the purposes of preparing a statement. * * @param connection Connection * @param schema Schema * @param schemaPath Path wherein to look for functions * @param objectPath Path of the object being analyzed (usually a view), * or null * @param propValues Connection properties * @return Context */ private static CalcitePrepare.Context makeContext( CalciteConnection connection, CalciteSchema schema, List<String> schemaPath, List<String> objectPath, final ImmutableMap<CalciteConnectionProperty, String> propValues) { if (connection == null) { final CalcitePrepare.Context context0 = CalcitePrepare.Dummy.peek(); final CalciteConnectionConfig config = mutate(context0.config(), propValues); return makeContext(config, context0.getTypeFactory(), context0.getDataContext(), schema, schemaPath, objectPath); } else { final CalciteConnectionConfig config = mutate(connection.config(), propValues); return makeContext(config, connection.getTypeFactory(), createDataContext(connection, schema.root().plus()), schema, schemaPath, objectPath); } }
public Expression getExpression(SchemaPlus parentSchema, String name) { return Schemas.subSchemaExpression(parentSchema, name, JdbcSchema.class); }
/** Returns a {@link Queryable}, given a fully-qualified table name. */ public static <E> Queryable<E> queryable(DataContext root, Class<E> clazz, String... names) { return queryable(root, clazz, Arrays.asList(names)); }
private static boolean matches(RelDataTypeFactory typeFactory, Function member, List<RelDataType> argumentTypes) { List<FunctionParameter> parameters = member.getParameters(); if (parameters.size() != argumentTypes.size()) { return false; } for (int i = 0; i < argumentTypes.size(); i++) { RelDataType argumentType = argumentTypes.get(i); FunctionParameter parameter = parameters.get(i); if (!canConvert(argumentType, parameter.getType(typeFactory))) { return false; } } return true; }
public TranslatableTable apply(List<Object> arguments) { final CalciteConnection connection = MaterializedViewTable.MATERIALIZATION_CONNECTION; CalcitePrepare.AnalyzeViewResult parsed = Schemas.analyzeView(connection, schema, schemaPath, viewSql, viewPath, modifiable != null && modifiable); final List<String> schemaPath1 = schemaPath != null ? schemaPath : schema.path(null); if ((modifiable == null || modifiable) && parsed.modifiable && parsed.table != null) { return modifiableViewTable(parsed, viewSql, schemaPath1, viewPath, schema); } else { return viewTable(parsed, viewSql, schemaPath1, viewPath); } }
/** Creates a path with a given list of names starting from a given root * schema. */ public static Path path(CalciteSchema rootSchema, Iterable<String> names) { final ImmutableList.Builder<Pair<String, Schema>> builder = ImmutableList.builder(); Schema schema = rootSchema.plus(); final Iterator<String> iterator = names.iterator(); if (!iterator.hasNext()) { return PathImpl.EMPTY; } if (!rootSchema.name.isEmpty()) { Preconditions.checkState(rootSchema.name.equals(iterator.next())); } for (;;) { final String name = iterator.next(); builder.add(Pair.of(name, schema)); if (!iterator.hasNext()) { return path(builder.build()); } schema = schema.getSubSchema(name); } }
@Override protected List<LatticeEntry> getLattices() { return Schemas.getLatticeEntries(schema); } }
public Enumerator<Object> enumerator() { final DataContext dataContext = Schemas.createDataContext(connection, calciteSignature.rootSchema.plus()); return calciteSignature.enumerable(dataContext).enumerator(); }
@Test public void testTableWhere() throws SQLException, ClassNotFoundException { final Connection connection = CalciteAssert.that(CalciteAssert.Config.JDBC_FOODMART).connect(); final CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class); final SchemaPlus rootSchema = calciteConnection.getRootSchema(); ParameterExpression c = Expressions.parameter(JdbcTest.Customer.class, "c"); String s = Schemas.queryable(Schemas.createDataContext(connection, rootSchema), rootSchema.getSubSchema("foodmart"), JdbcTest.Customer.class, "customer") .where( Expressions.lambda( Expressions.lessThan( Expressions.field(c, "customer_id"), Expressions.constant(5)), c)) .toList() .toString(); Util.discard(s); } }
/** * Creates a context for the purposes of preparing a statement. * * @param connection Connection * @param schema Schema * @param schemaPath Path wherein to look for functions * @param objectPath Path of the object being analyzed (usually a view), * or null * @param propValues Connection properties * @return Context */ private static CalcitePrepare.Context makeContext( CalciteConnection connection, CalciteSchema schema, List<String> schemaPath, List<String> objectPath, final ImmutableMap<CalciteConnectionProperty, String> propValues) { if (connection == null) { final CalcitePrepare.Context context0 = CalcitePrepare.Dummy.peek(); final CalciteConnectionConfig config = mutate(context0.config(), propValues); return makeContext(config, context0.getTypeFactory(), context0.getDataContext(), schema, schemaPath, objectPath); } else { final CalciteConnectionConfig config = mutate(connection.config(), propValues); return makeContext(config, connection.getTypeFactory(), createDataContext(connection, schema.root().plus()), schema, schemaPath, objectPath); } }
public Expression getExpression(SchemaPlus parentSchema, String name) { return Schemas.subSchemaExpression(parentSchema, name, JdbcSchema.class); }
/** Returns a {@link Queryable}, given a fully-qualified table name. */ public static <E> Queryable<E> queryable(DataContext root, Class<E> clazz, String... names) { return queryable(root, clazz, Arrays.asList(names)); }
private static boolean matches(RelDataTypeFactory typeFactory, Function member, List<RelDataType> argumentTypes) { List<FunctionParameter> parameters = member.getParameters(); if (parameters.size() != argumentTypes.size()) { return false; } for (int i = 0; i < argumentTypes.size(); i++) { RelDataType argumentType = argumentTypes.get(i); FunctionParameter parameter = parameters.get(i); if (!canConvert(argumentType, parameter.getType(typeFactory))) { return false; } } return true; }
public TranslatableTable apply(List<Object> arguments) { final CalciteConnection connection = MaterializedViewTable.MATERIALIZATION_CONNECTION; CalcitePrepare.AnalyzeViewResult parsed = Schemas.analyzeView(connection, schema, schemaPath, viewSql, viewPath, modifiable != null && modifiable); final List<String> schemaPath1 = schemaPath != null ? schemaPath : schema.path(null); if ((modifiable == null || modifiable) && parsed.modifiable && parsed.table != null) { return modifiableViewTable(parsed, viewSql, schemaPath1, viewPath, schema); } else { return viewTable(parsed, viewSql, schemaPath1, viewPath); } }
public Expression getExpression(SchemaPlus schema, String tableName, Class clazz) { return Schemas.tableExpression(schema, elementType, tableName, clazz); } }