org.apache.calcite.linq4j.QueryProvider Java Examples
The following examples show how to use
org.apache.calcite.linq4j.QueryProvider.
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: PreferredAlbumsTableFactory.java From calcite with Apache License 2.0 | 6 votes |
@Override public AbstractQueryableTable create( SchemaPlus schema, String name, Map<String, Object> operand, RelDataType rowType) { return new AbstractQueryableTable(Integer.class) { @Override public RelDataType getRowType(RelDataTypeFactory typeFactory) { return typeFactory.builder().add("ID", SqlTypeName.INTEGER).build(); } @Override public Queryable<Integer> asQueryable( QueryProvider qp, SchemaPlus sp, String string) { return fetchPreferredAlbums(); } }; }
Example #2
Source File: InstanceIdsByClassTable.java From mat-calcite-plugin with Apache License 2.0 | 6 votes |
@Override public Queryable<Integer> asQueryable(QueryProvider queryProvider, SchemaPlus schemaPlus, String tableName) { return new AbstractTableQueryable<Integer>(queryProvider, schemaPlus, this, tableName) { @Override public Enumerator<Integer> enumerator() { FluentIterable<Integer> it = FluentIterable .from(classesList.getClasses()) .transformAndConcat( new Function<IClass, Iterable<Integer>>() { @Override public Iterable<Integer> apply(IClass input) { try { return Ints.asList(input .getObjectIds()); } catch (SnapshotException e) { e.printStackTrace(); return Collections.emptyList(); } } }); return Linq4j.iterableEnumerator(it); } }; }
Example #3
Source File: OutboundReferencesTable.java From mat-calcite-plugin with Apache License 2.0 | 6 votes |
@Override public Queryable<Object[]> asQueryable(QueryProvider queryProvider, SchemaPlus schemaPlus, String tableName) { return new AbstractTableQueryable<Object[]>(queryProvider, schemaPlus, this, tableName) { @Override public Enumerator<Object[]> enumerator() { FluentIterable<Object[]> it = FluentIterable .from(references) .transform(new Function<NamedReference, Object[]>() { @Nullable @Override public Object[] apply(@Nullable NamedReference namedReference) { HeapReference ref = null; try { ref = HeapReference.valueOf(namedReference.getObject()); } catch (SnapshotException e) { e.printStackTrace(); } return new Object[]{namedReference.getName(), ref}; } }); return Linq4j.iterableEnumerator(it); } }; }
Example #4
Source File: ReflectiveSchemaTest.java From calcite with Apache License 2.0 | 6 votes |
@Test void testQueryProviderSingleColumn() throws Exception { Connection connection = CalciteAssert .that(CalciteAssert.Config.REGULAR).connect(); QueryProvider queryProvider = connection.unwrap(QueryProvider.class); ParameterExpression e = Expressions.parameter(Employee.class, "e"); // "Enumerable<T> asEnumerable(final T[] ts)" List<Integer> list = queryProvider.createQuery( Expressions.call( Expressions.call( Types.of(Enumerable.class, Employee.class), null, LINQ4J_AS_ENUMERABLE_METHOD, Expressions.constant(new JdbcTest.HrSchema().emps)), "asQueryable"), Employee.class) .select( Expressions.<Function1<Employee, Integer>>lambda( Expressions.field(e, "empid"), e)) .toList(); assertEquals(Arrays.asList(100, 200, 150, 110), list); }
Example #5
Source File: Smalls.java From calcite with Apache License 2.0 | 6 votes |
/** * A function that sums the second column of first input cursor, second * column of first input and the given int. */ public static QueryableTable processCursors(final int offset, final Enumerable<Object[]> a, final Enumerable<IntString> b) { return new AbstractQueryableTable(Object[].class) { public RelDataType getRowType(RelDataTypeFactory typeFactory) { return typeFactory.builder() .add("result", SqlTypeName.INTEGER) .build(); } public <T> Queryable<T> asQueryable(QueryProvider queryProvider, SchemaPlus schema, String tableName) { final Enumerable<Integer> enumerable = a.zip(b, (v0, v1) -> ((Integer) v0[1]) + v1.n + offset); //noinspection unchecked return (Queryable) enumerable.asQueryable(); } }; }
Example #6
Source File: Smalls.java From calcite with Apache License 2.0 | 6 votes |
/** * A function that adds a number to the first column of input cursor */ public static QueryableTable processCursor(final int offset, final Enumerable<Object[]> a) { return new AbstractQueryableTable(Object[].class) { public RelDataType getRowType(RelDataTypeFactory typeFactory) { return typeFactory.builder() .add("result", SqlTypeName.INTEGER) .build(); } public <T> Queryable<T> asQueryable(QueryProvider queryProvider, SchemaPlus schema, String tableName) { final Enumerable<Integer> enumerable = a.select(a0 -> offset + ((Integer) a0[0])); //noinspection unchecked return (Queryable) enumerable.asQueryable(); } }; }
Example #7
Source File: CodesFunction.java From calcite with Apache License 2.0 | 6 votes |
public static QueryableTable getTable(String name) { return new AbstractQueryableTable(Object[].class) { @Override public RelDataType getRowType(RelDataTypeFactory typeFactory) { return typeFactory.builder() .add("TYPE", SqlTypeName.VARCHAR) .add("CODEVALUE", SqlTypeName.VARCHAR) .build(); } @Override public Queryable<String[]> asQueryable(QueryProvider queryProvider, SchemaPlus schema, String tableName) { if (name == null) { return Linq4j.<String[]>emptyEnumerable().asQueryable(); } return Linq4j.asEnumerable(new String[][]{ new String[]{"HASHCODE", "" + name.hashCode()}, new String[]{"BASE64", Base64.getEncoder().encodeToString(name.getBytes(StandardCharsets.UTF_8))} }).asQueryable(); } }; }
Example #8
Source File: PreferredGenresTableFactory.java From calcite with Apache License 2.0 | 6 votes |
@Override public AbstractQueryableTable create( SchemaPlus schema, String name, Map<String, Object> operand, RelDataType rowType) { return new AbstractQueryableTable(Integer.class) { @Override public RelDataType getRowType(RelDataTypeFactory typeFactory) { return typeFactory.builder().add("ID", SqlTypeName.INTEGER).build(); } @Override public Queryable<Integer> asQueryable( QueryProvider qp, SchemaPlus sp, String string) { return fetchPreferredGenres(); } }; }
Example #9
Source File: Smalls.java From calcite with Apache License 2.0 | 6 votes |
private static QueryableTable oneThreePlus(String s) { List<Integer> items; // Argument is null in case SQL contains function call with expression. // Then the engine calls a function with null arguments to get getRowType. if (s == null) { items = ImmutableList.of(); } else { Integer latest = Integer.parseInt(s.substring(1, s.length() - 1)); items = ImmutableList.of(1, 3, latest); } final Enumerable<Integer> enumerable = Linq4j.asEnumerable(items); return new AbstractQueryableTable(Integer.class) { public <E> Queryable<E> asQueryable( QueryProvider queryProvider, SchemaPlus schema, String tableName) { //noinspection unchecked return (Queryable<E>) enumerable.asQueryable(); } public RelDataType getRowType(RelDataTypeFactory typeFactory) { return typeFactory.builder().add("c", SqlTypeName.INTEGER).build(); } }; }
Example #10
Source File: ListTable.java From calcite with Apache License 2.0 | 6 votes |
public <T> Queryable<T> asQueryable(final QueryProvider queryProvider, SchemaPlus schema, String tableName) { return new AbstractQueryable<T>() { public Type getElementType() { return elementType; } public Expression getExpression() { return expression; } public QueryProvider getProvider() { return queryProvider; } public Iterator<T> iterator() { //noinspection unchecked return list.iterator(); } public Enumerator<T> enumerator() { //noinspection unchecked return Linq4j.enumerator(list); } }; }
Example #11
Source File: TableDataContexImpl.java From marble with Apache License 2.0 | 6 votes |
public TableDataContexImpl(QueryProvider queryProvider, SchemaPlus rootSchema, JavaTypeFactory typeFactory, TableConfig tableConfig) { this.queryProvider = queryProvider; this.typeFactory = typeFactory; this.rootSchema = rootSchema; final long time = System.currentTimeMillis(); final TimeZone timeZone = tableConfig.getTimeZone(); final long localOffset = timeZone.getOffset(time); final long currentOffset = localOffset; ImmutableMap.Builder<Object, Object> builder = ImmutableMap.builder(); builder.put(Variable.UTC_TIMESTAMP.camelName, time) .put(Variable.CURRENT_TIMESTAMP.camelName, time + currentOffset) .put(Variable.LOCAL_TIMESTAMP.camelName, time + localOffset) .put(Variable.TIME_ZONE.camelName, timeZone); map = builder.build(); }
Example #12
Source File: TableInRootSchemaTest.java From calcite with Apache License 2.0 | 5 votes |
public <T> Queryable<T> asQueryable(QueryProvider queryProvider, SchemaPlus schema, String tableName) { return new AbstractTableQueryable<T>(queryProvider, schema, this, tableName) { public Enumerator<T> enumerator() { //noinspection unchecked return (Enumerator<T>) enumeratorImpl(null); } }; }
Example #13
Source File: OLAPTable.java From kylin with Apache License 2.0 | 5 votes |
@Override public <T> Queryable<T> asQueryable(QueryProvider queryProvider, SchemaPlus schema, String tableName) { return new AbstractTableQueryable<T>(queryProvider, schema, this, tableName) { @SuppressWarnings("unchecked") public Enumerator<T> enumerator() { final OLAPQuery query = new OLAPQuery(EnumeratorTypeEnum.OLAP, 0); return (Enumerator<T>) query.enumerator(); } }; }
Example #14
Source File: QuarkViewTable.java From quark with Apache License 2.0 | 5 votes |
public <T> Queryable<T> asQueryable(final QueryProvider queryProvider, SchemaPlus schema, String tableName) { return new AbstractTableQueryable<T>(queryProvider, schema, this, tableName) { @SuppressWarnings("unchecked") public Enumerator<T> enumerator() { return null; } }; }
Example #15
Source File: OLAPTable.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
@Override public <T> Queryable<T> asQueryable(QueryProvider queryProvider, SchemaPlus schema, String tableName) { return new AbstractTableQueryable<T>(queryProvider, schema, this, tableName) { @SuppressWarnings("unchecked") public Enumerator<T> enumerator() { final OLAPQuery query = new OLAPQuery(EnumeratorTypeEnum.OLAP, 0); return (Enumerator<T>) query.enumerator(); } }; }
Example #16
Source File: DataTable.java From marble with Apache License 2.0 | 5 votes |
public <T> Queryable<T> asQueryable(QueryProvider queryProvider, SchemaPlus schema, String tableName) { return new DataTableQueryable<T>(queryProvider, schema, this, tableName) { public Enumerator<T> enumerator() { //noinspection unchecked return (Enumerator<T>) Linq4j.enumerator(rows); } public List getRows() { return rows; } }; }
Example #17
Source File: TableFunctions.java From mat-calcite-plugin with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public <T> Queryable<T> asQueryable(QueryProvider queryProvider, SchemaPlus schemaPlus, String s) { BaseQueryable<RowType> queryable = new BaseQueryable<RowType>(null, getElementType(), null) { @Override public Enumerator<RowType> enumerator() { return Linq4j.enumerator(values); } }; return (Queryable<T>) queryable; }
Example #18
Source File: MycatReflectiveSchema.java From Mycat2 with GNU General Public License v3.0 | 5 votes |
public <T> Queryable<T> asQueryable(QueryProvider queryProvider, SchemaPlus schema, String tableName) { return new AbstractTableQueryable<T>(queryProvider, schema, this, tableName) { @SuppressWarnings("unchecked") public Enumerator<T> enumerator() { return (Enumerator<T>) enumerable.get(); } }; }
Example #19
Source File: MutableArrayTable.java From calcite with Apache License 2.0 | 5 votes |
public <T> Queryable<T> asQueryable(QueryProvider queryProvider, SchemaPlus schema, String tableName) { return new AbstractTableQueryable<T>(queryProvider, schema, this, tableName) { public Enumerator<T> enumerator() { //noinspection unchecked return (Enumerator<T>) Linq4j.enumerator(rows); } }; }
Example #20
Source File: ExtensionDdlExecutor.java From calcite with Apache License 2.0 | 5 votes |
public <T> Queryable<T> asQueryable(QueryProvider queryProvider, SchemaPlus schema, String tableName) { return new AbstractTableQueryable<T>(queryProvider, schema, this, tableName) { public Enumerator<T> enumerator() { //noinspection unchecked return (Enumerator<T>) Linq4j.enumerator(list); } }; }
Example #21
Source File: TpcdsSchema.java From calcite with Apache License 2.0 | 5 votes |
public <T> Queryable<T> asQueryable(final QueryProvider queryProvider, final SchemaPlus schema, final String tableName) { //noinspection unchecked return (Queryable) new AbstractTableQueryable<Object[]>(queryProvider, schema, this, tableName) { public Enumerator<Object[]> enumerator() { final Session session = Session.getDefaultSession() .withTable(tpcdsTable) .withScale(scaleFactor); final Results results = Results.constructResults(tpcdsTable, session); return Linq4j.asEnumerable(results) .selectMany( new Function1<List<List<String>>, Enumerable<Object[]>>() { final Column[] columns = tpcdsTable.getColumns(); public Enumerable<Object[]> apply( List<List<String>> inRows) { final List<Object[]> rows = new ArrayList<>(); for (List<String> strings : inRows) { final Object[] values = new Object[columns.length]; for (int i = 0; i < strings.size(); i++) { values[i] = convert(strings.get(i), columns[i]); } rows.add(values); } return Linq4j.asEnumerable(rows); } }) .enumerator(); } }; }
Example #22
Source File: Smalls.java From calcite with Apache License 2.0 | 5 votes |
/** A function that generates multiplication table of {@code ncol} columns x * {@code nrow} rows. */ public static QueryableTable multiplicationTable(final int ncol, final int nrow, Integer offset) { final int offs = offset == null ? 0 : offset; return new AbstractQueryableTable(Object[].class) { public RelDataType getRowType(RelDataTypeFactory typeFactory) { final RelDataTypeFactory.Builder builder = typeFactory.builder(); builder.add("row_name", typeFactory.createJavaType(String.class)); final RelDataType int_ = typeFactory.createJavaType(int.class); for (int i = 1; i <= ncol; i++) { builder.add("c" + i, int_); } return builder.build(); } public Queryable<Object[]> asQueryable(QueryProvider queryProvider, SchemaPlus schema, String tableName) { final List<Object[]> table = new AbstractList<Object[]>() { @Override public Object[] get(int index) { Object[] cur = new Object[ncol + 1]; cur[0] = "row " + index; for (int j = 1; j <= ncol; j++) { cur[j] = j * (index + 1) + offs; } return cur; } @Override public int size() { return nrow; } }; return Linq4j.asEnumerable(table).asQueryable(); } }; }
Example #23
Source File: CalciteMetaImpl.java From calcite with Apache License 2.0 | 5 votes |
public <T> Queryable<T> asQueryable(QueryProvider queryProvider, SchemaPlus schema, String tableName) { return new AbstractTableQueryable<T>(queryProvider, schema, this, tableName) { @SuppressWarnings("unchecked") public Enumerator<T> enumerator() { return (Enumerator<T>) MetadataTable.this.enumerator( ((CalciteConnectionImpl) queryProvider).meta()); } }; }
Example #24
Source File: Table.java From kareldb with Apache License 2.0 | 5 votes |
@Override public <T> Queryable<T> asQueryable(QueryProvider queryProvider, SchemaPlus schema, String tableName) { return new AbstractTableQueryable<T>(queryProvider, schema, this, tableName) { public Enumerator<T> enumerator() { //noinspection unchecked return (Enumerator<T>) Linq4j.iterableEnumerator( () -> Iterators.transform(getModifiableCollection().iterator(), Table::toArray)); } }; }
Example #25
Source File: ReflectiveSchema.java From calcite with Apache License 2.0 | 5 votes |
public <T> Queryable<T> asQueryable(QueryProvider queryProvider, SchemaPlus schema, String tableName) { return new AbstractTableQueryable<T>(queryProvider, schema, this, tableName) { @SuppressWarnings("unchecked") public Enumerator<T> enumerator() { return (Enumerator<T>) enumerable.enumerator(); } }; }
Example #26
Source File: RangeTable.java From calcite with Apache License 2.0 | 5 votes |
public <T> Queryable<T> asQueryable(QueryProvider queryProvider, SchemaPlus schema, String tableName) { return new AbstractTableQueryable<T>(queryProvider, schema, this, tableName) { public Enumerator<T> enumerator() { //noinspection unchecked return (Enumerator<T>) RangeTable.this.enumerator(); } }; }
Example #27
Source File: CloneSchema.java From calcite with Apache License 2.0 | 5 votes |
private Table createCloneTable(QueryProvider queryProvider, QueryableTable sourceTable, String name) { final Queryable<Object> queryable = sourceTable.asQueryable(queryProvider, sourceSchema, name); final JavaTypeFactory typeFactory = ((CalciteConnection) queryProvider).getTypeFactory(); return createCloneTable(typeFactory, Schemas.proto(sourceTable), ImmutableList.of(), null, queryable); }
Example #28
Source File: ArrayTable.java From calcite with Apache License 2.0 | 5 votes |
public <T> Queryable<T> asQueryable(final QueryProvider queryProvider, SchemaPlus schema, String tableName) { return new AbstractTableQueryable<T>(queryProvider, schema, this, tableName) { @SuppressWarnings("unchecked") public Enumerator<T> enumerator() { final Content content = supplier.get(); return content.enumerator(); } }; }
Example #29
Source File: ListTransientTable.java From calcite with Apache License 2.0 | 5 votes |
@Override public <T> Queryable<T> asQueryable(QueryProvider queryProvider, SchemaPlus schema, String tableName) { return new AbstractTableQueryable<T>(queryProvider, schema, this, tableName) { public Enumerator<T> enumerator() { //noinspection unchecked return (Enumerator<T>) Linq4j.enumerator(rows); } }; }
Example #30
Source File: AbstractTableQueryable.java From calcite with Apache License 2.0 | 5 votes |
public AbstractTableQueryable(QueryProvider queryProvider, SchemaPlus schema, QueryableTable table, String tableName) { this.queryProvider = queryProvider; this.schema = schema; this.table = table; this.tableName = tableName; }