org.apache.calcite.schema.impl.AbstractTableQueryable Java Examples

The following examples show how to use org.apache.calcite.schema.impl.AbstractTableQueryable. 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: InstanceIdsByClassTable.java    From mat-calcite-plugin with Apache License 2.0 6 votes vote down vote up
@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 #2
Source File: OutboundReferencesTable.java    From mat-calcite-plugin with Apache License 2.0 6 votes vote down vote up
@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 #3
Source File: QueryableRelBuilder.java    From calcite with Apache License 2.0 6 votes vote down vote up
RelNode toRel(Queryable<T> queryable) {
  if (queryable instanceof QueryableDefaults.Replayable) {
    //noinspection unchecked
    ((QueryableDefaults.Replayable) queryable).replay(this);
    return rel;
  }
  if (queryable instanceof AbstractTableQueryable) {
    final AbstractTableQueryable tableQueryable =
        (AbstractTableQueryable) queryable;
    final QueryableTable table = tableQueryable.table;
    final CalciteSchema.TableEntry tableEntry =
        CalciteSchema.from(tableQueryable.schema)
            .add(tableQueryable.tableName, tableQueryable.table);
    final RelOptTableImpl relOptTable =
        RelOptTableImpl.create(null, table.getRowType(translator.typeFactory),
            tableEntry, null);
    if (table instanceof TranslatableTable) {
      return ((TranslatableTable) table).toRel(translator.toRelContext(),
          relOptTable);
    } else {
      return LogicalTableScan.create(translator.cluster, relOptTable, ImmutableList.of());
    }
  }
  return translator.translate(queryable.getExpression());
}
 
Example #4
Source File: Table.java    From kareldb with Apache License 2.0 5 votes vote down vote up
@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 #5
Source File: OLAPTable.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@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 #6
Source File: MycatReflectiveSchema.java    From Mycat2 with GNU General Public License v3.0 5 votes vote down vote up
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 #7
Source File: QuarkViewTable.java    From quark with Apache License 2.0 5 votes vote down vote up
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 #8
Source File: OLAPTable.java    From kylin with Apache License 2.0 5 votes vote down vote up
@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 #9
Source File: TpcdsSchema.java    From calcite with Apache License 2.0 5 votes vote down vote up
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 #10
Source File: MutableArrayTable.java    From calcite with Apache License 2.0 5 votes vote down vote up
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 #11
Source File: CalciteMetaImpl.java    From calcite with Apache License 2.0 5 votes vote down vote up
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 #12
Source File: ReflectiveSchema.java    From calcite with Apache License 2.0 5 votes vote down vote up
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 #13
Source File: ArrayTable.java    From calcite with Apache License 2.0 5 votes vote down vote up
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 #14
Source File: RangeTable.java    From calcite with Apache License 2.0 5 votes vote down vote up
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 #15
Source File: TableInRootSchemaTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
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 #16
Source File: ExtensionDdlExecutor.java    From calcite with Apache License 2.0 5 votes vote down vote up
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);
    }
  };
}