@Override protected Void visitIdentifier(Identifier node, Integer indentLevel) { QualifiedName resolved = resolvedNameReferences.get(node); String resolvedName = ""; if (resolved != null) { resolvedName = "=>" + resolved.toString(); } print(indentLevel, "Identifier[" + node.getValue() + resolvedName + "]"); return null; }
@Override public Expression rewriteIdentifier(Identifier node, Void context, ExpressionTreeRewriter<Void> treeRewriter) { return new SymbolReference(node.getValue()); }
@Override protected Void visitIdentifier(Identifier node, ImmutableSet.Builder<QualifiedName> builder) { builder.add(QualifiedName.of(node.getValue())); return null; } }
@Override protected Void visitIdentifier(Identifier node, Set<String> lambdaArgumentNames) { if (analysis.getLambdaArgumentReferences().containsKey(NodeRef.of(node)) && !lambdaArgumentNames.contains(node.getValue())) { freeReferencesToLambdaArgument.add(node); } return null; }
public static Map<String, Expression> mapFromProperties(List<Property> properties) { return properties.stream().collect(toImmutableMap( property -> property.getName().getValue(), Property::getValue)); } }
private void validateProperties(List<Property> properties, Optional<Scope> scope) { Set<String> propertyNames = new HashSet<>(); for (Property property : properties) { if (!propertyNames.add(property.getName().getValue())) { throw new SemanticException(DUPLICATE_PROPERTY, property, "Duplicate property: %s", property.getName().getValue()); } } for (Property property : properties) { process(property, scope); } }
@Override public ListenableFuture<?> execute(Deallocate statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters) { String statementName = statement.getName().getValue(); stateMachine.removePreparedStatement(statementName); return immediateFuture(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); }
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; }
private static List<ColumnMetadata> getOutputTableColumns(RelationPlan plan, Optional<List<Identifier>> columnAliases) { ImmutableList.Builder<ColumnMetadata> columns = ImmutableList.builder(); int aliasPosition = 0; for (Field field : plan.getDescriptor().getVisibleFields()) { String columnName = columnAliases.isPresent() ? columnAliases.get().get(aliasPosition).getValue() : field.getName().get(); columns.add(new ColumnMetadata(columnName, field.getType())); aliasPosition++; } return columns.build(); }
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; }
@Override protected Object visitIdentifier(Identifier node, Object context) { // Identifier only exists before planning. // ExpressionInterpreter should only be invoked after planning. // As a result, this method should be unreachable. // However, RelationPlanner.visitUnnest and visitValues invokes evaluateConstantExpression. return ((SymbolResolver) context).getValue(new Symbol(node.getValue())); }
public String getPreparedStatementFromExecute(Execute execute) { return getPreparedStatement(execute.getName().getValue()); }
@Override public Expression rewriteLambdaExpression(LambdaExpression node, Void context, ExpressionTreeRewriter<Void> treeRewriter) { for (LambdaArgumentDeclaration argument : node.getArguments()) { String argumentName = argument.getName().getValue(); // Symbol names are unique. As a result, a symbol should never be excluded multiple times. checkArgument(!excludedNames.contains(argumentName)); excludedNames.add(argumentName); } Expression result = treeRewriter.defaultRewrite(node, context); for (LambdaArgumentDeclaration argument : node.getArguments()) { excludedNames.remove(argument.getName().getValue()); } return result; } }
@Override public ListenableFuture<?> execute(Prepare prepare, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters) { Statement statement = prepare.getStatement(); if ((statement instanceof Prepare) || (statement instanceof Execute) || (statement instanceof Deallocate)) { String type = statement.getClass().getSimpleName().toUpperCase(ENGLISH); throw new PrestoException(NOT_SUPPORTED, "Invalid statement type for prepared statement: " + type); } String sql = getFormattedSql(statement, sqlParser, Optional.empty()); stateMachine.addPreparedStatement(prepare.getName().getValue(), sql); return immediateFuture(null); } }
@Override public ListenableFuture<?> execute(Use statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters) { Session session = stateMachine.getSession(); if (!statement.getCatalog().isPresent() && !session.getCatalog().isPresent()) { throw new SemanticException(CATALOG_NOT_SPECIFIED, statement, "Catalog must be specified when session catalog is not set"); } if (statement.getCatalog().isPresent()) { String catalog = statement.getCatalog().get().getValue().toLowerCase(ENGLISH); if (!metadata.getCatalogHandle(session, catalog).isPresent()) { throw new PrestoException(NOT_FOUND, "Catalog does not exist: " + catalog); } stateMachine.setSetCatalog(catalog); } stateMachine.setSetSchema(statement.getSchema().getValue().toLowerCase(ENGLISH)); return immediateFuture(null); } }
public Symbol newSymbol(Expression expression, Type type, String suffix) { String nameHint = "expr"; if (expression instanceof Identifier) { nameHint = ((Identifier) expression).getValue(); } else if (expression instanceof FunctionCall) { nameHint = ((FunctionCall) expression).getName().getSuffix(); } else if (expression instanceof SymbolReference) { nameHint = ((SymbolReference) expression).getName(); } else if (expression instanceof GroupingOperation) { nameHint = "grouping"; } return newSymbol(nameHint, type, suffix); }
@Override protected Type visitIdentifier(Identifier node, StackableAstVisitorContext<Context> context) { ResolvedField resolvedField = context.getContext().getScope().resolveField(node, QualifiedName.of(node.getValue())); return handleResolvedField(node, resolvedField, context); }
@Override public ListenableFuture<?> execute(RenameSchema statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters) { Session session = stateMachine.getSession(); CatalogSchemaName source = createCatalogSchemaName(session, statement, Optional.of(statement.getSource())); CatalogSchemaName target = new CatalogSchemaName(source.getCatalogName(), statement.getTarget().getValue()); if (!metadata.schemaExists(session, source)) { throw new SemanticException(MISSING_SCHEMA, statement, "Schema '%s' does not exist", source); } if (metadata.schemaExists(session, target)) { throw new SemanticException(SCHEMA_ALREADY_EXISTS, statement, "Target schema '%s' already exists", target); } accessControl.checkCanRenameSchema(session.getRequiredTransactionId(), session.getIdentity(), source, statement.getTarget().getValue()); metadata.renameSchema(session, source, statement.getTarget().getValue()); return immediateFuture(null); } }