use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Table in project calcite by apache.
the class ModelHandler method visit.
public void visit(JsonCustomTable jsonTable) {
try {
checkRequiredAttributes(jsonTable, "name", "factory");
final SchemaPlus schema = currentMutableSchema("table");
final TableFactory tableFactory = AvaticaUtils.instantiatePlugin(TableFactory.class, jsonTable.factory);
final Table table = tableFactory.create(schema, jsonTable.name, operandMap(null, jsonTable.operand), null);
for (JsonColumn column : jsonTable.columns) {
column.accept(this);
}
schema.add(jsonTable.name, table);
} catch (Exception e) {
throw new RuntimeException("Error instantiating " + jsonTable, e);
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Table in project calcite by apache.
the class SimpleCalciteSchema method addImplicitTablesBasedOnNullaryFunctionsToBuilder.
protected void addImplicitTablesBasedOnNullaryFunctionsToBuilder(ImmutableSortedMap.Builder<String, Table> builder) {
ImmutableSortedMap<String, Table> explicitTables = builder.build();
for (String s : schema.getFunctionNames()) {
// explicit table wins.
if (explicitTables.containsKey(s)) {
continue;
}
for (Function function : schema.getFunctions(s)) {
if (function instanceof TableMacro && function.getParameters().isEmpty()) {
final Table table = ((TableMacro) function).apply(ImmutableList.of());
builder.put(s, table);
}
}
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Table in project calcite by apache.
the class LogicalTableScan method create.
/**
* Creates a LogicalTableScan.
*
* @param cluster Cluster
* @param relOptTable Table
*/
public static LogicalTableScan create(RelOptCluster cluster, final RelOptTable relOptTable) {
final Table table = relOptTable.unwrap(Table.class);
final RelTraitSet traitSet = cluster.traitSetOf(Convention.NONE).replaceIfs(RelCollationTraitDef.INSTANCE, new Supplier<List<RelCollation>>() {
public List<RelCollation> get() {
if (table != null) {
return table.getStatistic().getCollations();
}
return ImmutableList.of();
}
});
return new LogicalTableScan(cluster, traitSet, relOptTable);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Table in project calcite by apache.
the class ModifiableViewTable method extend.
/**
* Extends the underlying table and returns a new view with updated row-type
* and column-mapping.
*
* <p>The type factory is used to perform some scratch calculations, viz the
* type mapping, but the "real" row-type will be assigned later, when the
* table has been bound to the statement's type factory. The is important,
* because adding types to type factories that do not belong to a statement
* could potentially leak memory.
*
* @param extendedColumns Extended fields
* @param typeFactory Type factory
*/
public final ModifiableViewTable extend(List<RelDataTypeField> extendedColumns, RelDataTypeFactory typeFactory) {
final ExtensibleTable underlying = unwrap(ExtensibleTable.class);
assert underlying != null;
final RelDataTypeFactory.Builder builder = typeFactory.builder();
final RelDataType rowType = getRowType(typeFactory);
for (RelDataTypeField column : rowType.getFieldList()) {
builder.add(column);
}
for (RelDataTypeField column : extendedColumns) {
builder.add(column);
}
// The characteristics of the new view.
final RelDataType newRowType = builder.build();
final ImmutableIntList newColumnMapping = getNewColumnMapping(underlying, getColumnMapping(), extendedColumns, typeFactory);
// Extend the underlying table with only the fields that
// duplicate column names in neither the view nor the base table.
final List<RelDataTypeField> underlyingColumns = underlying.getRowType(typeFactory).getFieldList();
final List<RelDataTypeField> columnsOfExtendedBaseTable = RelOptUtil.deduplicateColumns(underlyingColumns, extendedColumns);
final List<RelDataTypeField> extendColumnsOfBaseTable = columnsOfExtendedBaseTable.subList(underlyingColumns.size(), columnsOfExtendedBaseTable.size());
final Table extendedTable = underlying.extend(extendColumnsOfBaseTable);
return extend(extendedTable, RelDataTypeImpl.proto(newRowType), newColumnMapping);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Table in project calcite by apache.
the class GeodeSimpleSchema method getTableMap.
@Override
protected Map<String, Table> getTableMap() {
if (tableMap == null) {
final ImmutableMap.Builder<String, Table> builder = ImmutableMap.builder();
for (String regionName : regionNames) {
Region region = GeodeUtils.createRegionProxy(clientCache, regionName);
// TODO: What if the region is empty
Object regionEntry = region.get(region.keySetOnServer().iterator().next());
Table table = new GeodeSimpleScannableTable(regionName, createRelDataType(regionEntry), clientCache);
builder.put(regionName, table);
}
tableMap = builder.build();
}
return tableMap;
}
Aggregations