use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier in project hazelcast by hazelcast.
the class HazelcastSqlValidator method isHiddenColumn.
private boolean isHiddenColumn(SqlNode node, SelectScope scope) {
if (!(node instanceof SqlIdentifier)) {
return false;
}
SqlIdentifier identifier = (SqlIdentifier) node;
String fieldName = extractFieldName(identifier, scope);
if (fieldName == null) {
return false;
}
SqlValidatorTable table = scope.fullyQualify(identifier).namespace.getTable();
if (table == null) {
return false;
}
HazelcastTable unwrappedTable = table.unwrap(HazelcastTable.class);
if (unwrappedTable == null) {
return false;
}
return unwrappedTable.isHidden(fieldName);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier 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 org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier 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 org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier in project hazelcast by hazelcast.
the class HazelcastDynamicTableFunction method findOperandByName.
private static SqlNode findOperandByName(String name, SqlCall call) {
for (int i = 0; i < call.operandCount(); i++) {
SqlCall assignment = call.operand(i);
SqlIdentifier id = assignment.operand(1);
if (name.equals(id.getSimple())) {
return assignment.operand(0);
}
}
return null;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier in project samza by apache.
the class SamzaSqlUdfOperatorTable method getSqlOperator.
private SqlOperator getSqlOperator(SamzaSqlScalarFunctionImpl scalarFunction, List<UdfMetadata> udfMetadataList) {
int numArguments = scalarFunction.numberOfArguments();
UdfMetadata udfMetadata = scalarFunction.getUdfMetadata();
if (udfMetadata.isDisableArgCheck()) {
return new SqlUserDefinedFunction(new SqlIdentifier(scalarFunction.getUdfName(), SqlParserPos.ZERO), o -> scalarFunction.getReturnType(o.getTypeFactory()), null, Checker.ANY_CHECKER, null, scalarFunction);
} else {
return new SqlUserDefinedFunction(new SqlIdentifier(scalarFunction.getUdfName(), SqlParserPos.ZERO), o -> scalarFunction.getReturnType(o.getTypeFactory()), null, Checker.getChecker(numArguments, numArguments, udfMetadata), null, scalarFunction);
}
}
Aggregations