use of com.hazelcast.sql.impl.schema.Table in project hazelcast by hazelcast.
the class CreateDagVisitor method onDelete.
public Vertex onDelete(DeletePhysicalRel rel) {
Table table = rel.getTable().unwrap(HazelcastTable.class).getTarget();
Vertex vertex = getJetSqlConnector(table).deleteProcessor(dag, table);
connectInput(rel.getInput(), vertex, null);
return vertex;
}
use of com.hazelcast.sql.impl.schema.Table in project hazelcast by hazelcast.
the class HazelcastSchemaUtils method createRootSchema.
/**
* Construct a schema from the given table resolvers.
* <p>
* Currently we assume that all tables are resolved upfront by querying a table resolver. It works well for predefined
* objects such as IMap and ReplicatedMap as well as external tables created by Jet. This approach will not work well
* should we need a relaxed/dynamic object resolution at some point in future.
*
* @return Top-level schema.
*/
public static HazelcastSchema createRootSchema(SqlCatalog catalog) {
// Create schemas.
Map<String, Schema> schemaMap = new HashMap<>();
for (Map.Entry<String, Map<String, Table>> currentSchemaEntry : catalog.getSchemas().entrySet()) {
String schemaName = currentSchemaEntry.getKey();
Map<String, org.apache.calcite.schema.Table> schemaTables = new HashMap<>();
for (Map.Entry<String, Table> tableEntry : currentSchemaEntry.getValue().entrySet()) {
String tableName = tableEntry.getKey();
Table table = tableEntry.getValue();
HazelcastTable convertedTable = new HazelcastTable(table, createTableStatistic(table));
schemaTables.put(tableName, convertedTable);
}
HazelcastSchema currentSchema = new HazelcastSchema(Collections.emptyMap(), schemaTables);
schemaMap.put(schemaName, currentSchema);
}
HazelcastSchema rootSchema = new HazelcastSchema(schemaMap, Collections.emptyMap());
return createCatalog(rootSchema);
}
use of com.hazelcast.sql.impl.schema.Table in project hazelcast by hazelcast.
the class HazelcastSqlValidator method createSourceSelectForUpdate.
@Override
protected SqlSelect createSourceSelectForUpdate(SqlUpdate update) {
SqlNodeList selectList = new SqlNodeList(SqlParserPos.ZERO);
Table table = extractTable((SqlIdentifier) update.getTargetTable());
if (table != null) {
if (table instanceof ViewTable) {
throw QueryException.error("DML operations not supported for views");
}
SqlConnector connector = getJetSqlConnector(table);
// only tables with primary keys can be updated
if (connector.getPrimaryKey(table).isEmpty()) {
throw QueryException.error("Cannot UPDATE " + update.getTargetTable() + ": it doesn't have a primary key");
}
// add all fields, even hidden ones...
table.getFields().forEach(field -> selectList.add(new SqlIdentifier(field.getName(), SqlParserPos.ZERO)));
}
int ordinal = 0;
for (SqlNode exp : update.getSourceExpressionList()) {
// Force unique aliases to avoid a duplicate for Y with
// SET X=Y
String alias = SqlUtil.deriveAliasFromOrdinal(ordinal);
selectList.add(SqlValidatorUtil.addAlias(exp, alias));
++ordinal;
}
SqlNode sourceTable = update.getTargetTable();
if (update.getAlias() != null) {
sourceTable = SqlValidatorUtil.addAlias(sourceTable, update.getAlias().getSimple());
}
return new SqlSelect(SqlParserPos.ZERO, null, selectList, sourceTable, update.getCondition(), null, null, null, null, null, null, null);
}
use of com.hazelcast.sql.impl.schema.Table in project hazelcast by hazelcast.
the class HazelcastSqlValidator method createSourceSelectForDelete.
@Override
protected SqlSelect createSourceSelectForDelete(SqlDelete delete) {
SqlNodeList selectList = new SqlNodeList(SqlParserPos.ZERO);
Table table = extractTable((SqlIdentifier) delete.getTargetTable());
if (table != null) {
if (table instanceof ViewTable) {
throw QueryException.error("DML operations not supported for views");
}
SqlConnector connector = getJetSqlConnector(table);
// We need to feed primary keys to the delete processor so that it can directly delete the records.
// Therefore we use the primary key for the select list.
connector.getPrimaryKey(table).forEach(name -> selectList.add(new SqlIdentifier(name, SqlParserPos.ZERO)));
if (selectList.size() == 0) {
throw QueryException.error("Cannot DELETE from " + delete.getTargetTable() + ": it doesn't have a primary key");
}
}
SqlNode sourceTable = delete.getTargetTable();
if (delete.getAlias() != null) {
sourceTable = SqlValidatorUtil.addAlias(sourceTable, delete.getAlias().getSimple());
}
return new SqlSelect(SqlParserPos.ZERO, null, selectList, sourceTable, delete.getCondition(), null, null, null, null, null, null, null);
}
Aggregations