@Override protected Object visitDereferenceExpression(DereferenceExpression node, Object context) Type type = type(node.getBase()); Object base = process(node.getBase(), context); return new DereferenceExpression(toExpression(base, type), node.getField()); Block row = (Block) base; Type returnType = type(node); String fieldName = node.getField().getValue(); List<Field> fields = rowType.getFields(); int index = -1; checkState(index >= 0, "could not find field name: %s", node.getField()); if (row.isNull(index)) { return null;
@Override protected Type visitDereferenceExpression(DereferenceExpression node, StackableAstVisitorContext<Context> context) QualifiedName qualifiedName = DereferenceExpression.getQualifiedName(node); Type baseType = process(node.getBase(), context); if (!(baseType instanceof RowType)) { throw new SemanticException(TYPE_MISMATCH, node.getBase(), "Expression %s is not of type ROW", node.getBase()); String fieldName = node.getField().getValue();
private static Expression name(String first, String... parts) { return DereferenceExpression.from(QualifiedName.of(first, parts)); } }
@Override protected Void visitDereferenceExpression(DereferenceExpression node, ImmutableSet.Builder<QualifiedName> builder) { if (columnReferences.contains(NodeRef.<Expression>of(node))) { builder.add(DereferenceExpression.getQualifiedName(node)); } else { process(node.getBase(), builder); } return null; }
public static String visitDereferenceExpression(DereferenceExpression node){ if(node.getBase() instanceof Identifier) { return ((Identifier)node.getBase()).getName()/*.getValue()*/+"."+node.getFieldName()/*.getValue()*/; }else return visitDereferenceExpression((DereferenceExpression)node.getBase())+"."+node.getFieldName()/*.getValue()*/; }
@Override protected R visitDereferenceExpression(DereferenceExpression node, C context) { process(node.getBase(), context); return null; }
@Override public Node visitDereference(SqlBaseParser.DereferenceContext context) { return new DereferenceExpression( getLocation(context), (Expression) visit(context.base), (Identifier) visit(context.fieldName)); }
@Override protected Type visitDereferenceExpression(DereferenceExpression node, StackableAstVisitorContext<AnalysisContext> context) QualifiedName qualifiedName = DereferenceExpression.getQualifiedName(node); Type baseType = process(node.getBase(), context); if (!(baseType instanceof RowType)) { throw new SemanticException(TYPE_MISMATCH, node.getBase(), "Expression %s is not of type ROW", node.getBase()); if (rowField.getName().equals(Optional.of(node.getFieldName()))) { rowFieldType = rowField.getType(); break;
private static List<String> tryParseParts(Expression base, String fieldName) { if (base instanceof Identifier) { return ImmutableList.of(((Identifier) base).getValue(), fieldName); } else if (base instanceof DereferenceExpression) { QualifiedName baseQualifiedName = getQualifiedName((DereferenceExpression) base); if (baseQualifiedName != null) { List<String> newList = new ArrayList<>(baseQualifiedName.getParts()); newList.add(fieldName); return newList; } } return null; }
/** * If this DereferenceExpression looks like a QualifiedName, return QualifiedName. * Otherwise return null */ public static QualifiedName getQualifiedName(DereferenceExpression expression) { List<String> parts = tryParseParts(expression.base, expression.field.getValue().toLowerCase(Locale.ENGLISH)); return parts == null ? null : QualifiedName.of(parts); }
@Override protected String visitDereferenceExpression(DereferenceExpression node, Boolean unmangleNames) { String baseString = process(node.getBase(), unmangleNames); return baseString + "." + formatIdentifier(node.getFieldName()); }
@Override protected RowExpression visitDereferenceExpression(DereferenceExpression node, Void context) { RowType rowType = (RowType) getType(node.getBase()); String fieldName = node.getField().getValue(); List<Field> fields = rowType.getFields(); int index = -1; for (int i = 0; i < fields.size(); i++) { Field field = fields.get(i); if (field.getName().isPresent() && field.getName().get().equalsIgnoreCase(fieldName)) { checkArgument(index < 0, "Ambiguous field %s in type %s", field, rowType.getDisplayName()); index = i; } } if (legacyRowFieldOrdinalAccess && index < 0) { OptionalInt rowIndex = parseAnonymousRowFieldOrdinalAccess(fieldName, fields); if (rowIndex.isPresent()) { index = rowIndex.getAsInt(); } } checkState(index >= 0, "could not find field name: %s", node.getField()); Type returnType = getType(node); return call(dereferenceSignature(returnType, rowType), returnType, process(node.getBase(), context), constant(index, INTEGER)); }
@Override protected Void visitDereferenceExpression(DereferenceExpression node, ImmutableSet.Builder<Expression> builder) { if (columnReferences.contains(NodeRef.<Expression>of(node))) { builder.add(node); } else { process(node.getBase(), builder); } return null; }
@Override protected Void visitDereferenceExpression(DereferenceExpression node, ImmutableSet.Builder<QualifiedName> builder) { if (columnReferences.contains(node)) { builder.add(DereferenceExpression.getQualifiedName(node)); } else { process(node.getBase(), builder); } return null; }
public static Expression from(QualifiedName name) { Expression result = null; for (String part : name.getParts()) { if (result == null) { result = new Identifier(part); } else { result = new DereferenceExpression(result, new Identifier(part)); } } return result; }
private static QualifiedName asQualifiedName(Expression expression) { QualifiedName name = null; if (expression instanceof Identifier) { name = QualifiedName.of(((Identifier) expression).getValue()); } else if (expression instanceof DereferenceExpression) { name = DereferenceExpression.getQualifiedName((DereferenceExpression) expression); } return name; }
/** * If this DereferenceExpression looks like a QualifiedName, return QualifiedName. * Otherwise return null */ public static QualifiedName getQualifiedName(DereferenceExpression expression) { List<String> parts = tryParseParts(expression.base, expression.fieldName); return parts == null ? null : new QualifiedName(parts); }
@Override protected String visitDereferenceExpression(DereferenceExpression node, Boolean unmangleNames) { String baseString = process(node.getBase(), unmangleNames); return baseString + "." + formatIdentifier(node.getFieldName()); }