use of com.hazelcast.jet.sql.impl.schema.HazelcastTable in project hazelcast by hazelcast.
the class SqlExtendedInsert method validate.
@Override
public void validate(SqlValidator validator, SqlValidatorScope scope) {
SqlValidatorTable table0 = validator.getCatalogReader().getTable(tableNames());
if (table0 == null) {
super.validate(validator, scope);
// should have failed with "Object not found"
assert false;
}
HazelcastTable table = table0.unwrap(HazelcastTable.class);
if (getTargetColumnList() == null) {
RelDataType rowType = table.getRowType(validator.getTypeFactory());
List<SqlNode> columnListWithoutHidden = new ArrayList<>();
for (RelDataTypeField f : rowType.getFieldList()) {
if (!table.isHidden(f.getName())) {
columnListWithoutHidden.add(new SqlIdentifier(f.getName(), SqlParserPos.ZERO));
}
}
overrideColumnList = new SqlNodeList(columnListWithoutHidden, SqlParserPos.ZERO);
}
super.validate(validator, scope);
Map<String, TableField> fieldsMap = table.getTarget().getFields().stream().collect(Collectors.toMap(TableField::getName, f -> f));
for (SqlNode fieldNode : getTargetColumnList()) {
TableField field = fieldsMap.get(((SqlIdentifier) fieldNode).getSimple());
if (field instanceof MapTableField) {
QueryPath path = ((MapTableField) field).getPath();
if (path.getPath() == null && field.getType().getTypeFamily() == QueryDataTypeFamily.OBJECT) {
throw validator.newValidationError(fieldNode, RESOURCE.insertToTopLevelObject());
}
}
}
}
use of com.hazelcast.jet.sql.impl.schema.HazelcastTable in project hazelcast by hazelcast.
the class IndexScanMapPhysicalRel method projection.
public List<Expression<?>> projection(QueryParameterMetadata parameterMetadata) {
PlanNodeSchema schema = OptUtils.schema(getTable());
HazelcastTable table = getTable().unwrap(HazelcastTable.class);
return project(schema, table.getProjects(), parameterMetadata);
}
use of com.hazelcast.jet.sql.impl.schema.HazelcastTable in project hazelcast by hazelcast.
the class OptUtils method extractKeyConstantExpression.
@SuppressWarnings("checkstyle:AvoidNestedBlocks")
public static RexNode extractKeyConstantExpression(RelOptTable relTable, RexBuilder rexBuilder) {
HazelcastTable table = relTable.unwrap(HazelcastTable.class);
RexNode filter = table.getFilter();
if (filter == null) {
return null;
}
int keyIndex = findKeyIndex(table.getTarget());
switch(filter.getKind()) {
// WHERE __key = true, calcite simplifies to just `WHERE __key`
case INPUT_REF:
{
return ((RexInputRef) filter).getIndex() == keyIndex ? rexBuilder.makeLiteral(true) : null;
}
// WHERE __key = false, calcite simplifies to `WHERE NOT __key`
case NOT:
{
RexNode operand = ((RexCall) filter).getOperands().get(0);
return operand.getKind() == SqlKind.INPUT_REF && ((RexInputRef) operand).getIndex() == keyIndex ? rexBuilder.makeLiteral(false) : null;
}
// __key = ...
case EQUALS:
{
Tuple2<Integer, RexNode> constantExpressionByIndex = extractConstantExpression((RexCall) filter);
// noinspection ConstantConditions
return constantExpressionByIndex != null && constantExpressionByIndex.getKey() == keyIndex ? constantExpressionByIndex.getValue() : null;
}
default:
return null;
}
}
use of com.hazelcast.jet.sql.impl.schema.HazelcastTable 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.schema.HazelcastTable 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);
}
Aggregations