use of org.apache.calcite.schema.Table in project calcite by apache.
the class Elasticsearch5Schema method getTableMap.
@Override
protected Map<String, Table> getTableMap() {
final ImmutableMap.Builder<String, Table> builder = ImmutableMap.builder();
try {
final GetMappingsResponse response = client.admin().indices().getMappings(new GetMappingsRequest().indices(index)).get();
ImmutableOpenMap<String, MappingMetaData> mapping = response.getMappings().get(index);
for (ObjectObjectCursor<String, MappingMetaData> c : mapping) {
builder.put(c.key, new Elasticsearch5Table(client, index, c.key));
}
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
return builder.build();
}
use of org.apache.calcite.schema.Table in project calcite by apache.
the class GeodeSchema method getTableMap.
@Override
protected Map<String, Table> getTableMap() {
if (tableMap == null) {
final ImmutableMap.Builder<String, Table> builder = ImmutableMap.builder();
// Extract the first entity of each Regions and use it to build a table types
for (String regionName : regionNames) {
Region region = GeodeUtils.createRegionProxy(clientCache, regionName);
Iterator regionIterator = region.keySetOnServer().iterator();
Object firstRegionEntry = region.get(regionIterator.next());
// TODO: how to handle empty Regions? JMX?
Table table = new GeodeTable(this, regionName, createRelDataType(firstRegionEntry), clientCache);
builder.put(regionName, table);
}
tableMap = builder.build();
}
return tableMap;
}
use of org.apache.calcite.schema.Table in project flink by apache.
the class FlinkCalciteCatalogReaderTest method testGetNonFlinkPreparingTableBase.
@Test
public void testGetNonFlinkPreparingTableBase() {
Table nonFlinkTableMock = mock(Table.class);
when(nonFlinkTableMock.getRowType(typeFactory)).thenReturn(mock(RelDataType.class));
rootSchemaPlus.add(tableMockName, nonFlinkTableMock);
Prepare.PreparingTable resultTable = catalogReader.getTable(Collections.singletonList(tableMockName));
assertFalse(resultTable instanceof FlinkPreparingTableBase);
}
use of org.apache.calcite.schema.Table in project flink by apache.
the class SqlValidatorImpl method checkConstraint.
/**
* Validates updates against the constraint of a modifiable view.
*
* @param validatorTable A {@link SqlValidatorTable} that may wrap a ModifiableViewTable
* @param update The UPDATE parse tree node
* @param targetRowType The target type
*/
private void checkConstraint(SqlValidatorTable validatorTable, SqlUpdate update, RelDataType targetRowType) {
final ModifiableViewTable modifiableViewTable = validatorTable.unwrap(ModifiableViewTable.class);
if (modifiableViewTable != null) {
final Table table = modifiableViewTable.unwrap(Table.class);
final RelDataType tableRowType = table.getRowType(typeFactory);
final Map<Integer, RexNode> projectMap = RelOptUtil.getColumnConstraints(modifiableViewTable, targetRowType, typeFactory);
final Map<String, Integer> nameToIndex = SqlValidatorUtil.mapNameToIndex(tableRowType.getFieldList());
// Validate update values against the view constraint.
final List<SqlNode> targets = update.getTargetColumnList().getList();
final List<SqlNode> sources = update.getSourceExpressionList().getList();
for (final Pair<SqlNode, SqlNode> column : Pair.zip(targets, sources)) {
final String columnName = ((SqlIdentifier) column.left).getSimple();
final Integer columnIndex = nameToIndex.get(columnName);
if (projectMap.containsKey(columnIndex)) {
final RexNode columnConstraint = projectMap.get(columnIndex);
final ValidationError validationError = new ValidationError(column.right, RESOURCE.viewConstraintNotSatisfied(columnName, Util.last(validatorTable.getQualifiedName())));
RelOptUtil.validateValueAgainstConstraint(column.right, columnConstraint, validationError);
}
}
}
}
use of org.apache.calcite.schema.Table in project flink by apache.
the class SqlValidatorImpl method isRolledUpColumnAllowedInAgg.
// Returns true iff the given column is valid inside the given aggCall.
private boolean isRolledUpColumnAllowedInAgg(SqlIdentifier identifier, SqlValidatorScope scope, SqlCall aggCall, SqlNode parent) {
Pair<String, String> pair = findTableColumnPair(identifier, scope);
if (pair == null) {
return true;
}
String columnName = pair.right;
SqlValidatorTable sqlValidatorTable = scope.fullyQualify(identifier).namespace.getTable();
if (sqlValidatorTable != null) {
Table table = sqlValidatorTable.unwrap(Table.class);
return table.rolledUpColumnValidInsideAgg(columnName, aggCall, parent, catalogReader.getConfig());
}
return true;
}
Aggregations