use of com.hazelcast.jet.sql.impl.connector.SqlConnector in project hazelcast by hazelcast.
the class HazelcastSqlValidator method containsStreamingSource.
/**
* Goes over all the referenced tables in the given {@link SqlNode}
* and returns true if any of them uses a streaming connector.
*/
public boolean containsStreamingSource(SqlNode node) {
class FindStreamingTablesVisitor extends SqlBasicVisitor<Void> {
boolean found;
@Override
public Void visit(SqlIdentifier id) {
SqlValidatorTable table = getCatalogReader().getTable(id.names);
// not every identifier is a table
if (table != null) {
HazelcastTable hazelcastTable = table.unwrap(HazelcastTable.class);
if (hazelcastTable.getTarget() instanceof ViewTable) {
found = ((ViewTable) hazelcastTable.getTarget()).isStream();
return null;
}
SqlConnector connector = getJetSqlConnector(hazelcastTable.getTarget());
if (connector.isStream()) {
found = true;
return null;
}
}
return super.visit(id);
}
@Override
public Void visit(SqlCall call) {
SqlOperator operator = call.getOperator();
if (operator instanceof HazelcastTableSourceFunction) {
if (((HazelcastTableSourceFunction) operator).isStream()) {
found = true;
return null;
}
}
return super.visit(call);
}
}
FindStreamingTablesVisitor visitor = new FindStreamingTablesVisitor();
node.accept(visitor);
return visitor.found;
}
use of com.hazelcast.jet.sql.impl.connector.SqlConnector 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.jet.sql.impl.connector.SqlConnector 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);
}
use of com.hazelcast.jet.sql.impl.connector.SqlConnector in project hazelcast by hazelcast.
the class TableResolverImpl method resolveMapping.
private Mapping resolveMapping(Mapping mapping) {
String type = mapping.type();
Map<String, String> options = mapping.options();
SqlConnector connector = connectorCache.forType(type);
List<MappingField> resolvedFields = connector.resolveAndValidateFields(nodeEngine, options, mapping.fields());
return new Mapping(mapping.name(), mapping.externalName(), type, new ArrayList<>(resolvedFields), new LinkedHashMap<>(options));
}
Aggregations