use of io.prestosql.sql.analyzer.Analysis in project hetu-core by openlookeng.
the class CreateViewTask method execute.
@Override
public ListenableFuture<?> execute(CreateView statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters, HeuristicIndexerManager heuristicIndexerManager) {
Session session = stateMachine.getSession();
QualifiedObjectName name = createQualifiedObjectName(session, statement, statement.getName());
accessControl.checkCanCreateView(session.getRequiredTransactionId(), session.getIdentity(), name);
String sql = getFormattedSql(statement.getQuery(), sqlParser, Optional.of(parameters));
Analysis analysis = analyzeStatement(statement, session, metadata, accessControl, parameters, stateMachine.getWarningCollector());
List<ViewColumn> columns = analysis.getOutputDescriptor(statement.getQuery()).getVisibleFields().stream().map(field -> new ViewColumn(field.getName().get(), field.getType().getTypeSignature())).collect(toImmutableList());
// use DEFINER security by default
Optional<String> owner = Optional.of(session.getUser());
if (statement.getSecurity().orElse(null) == INVOKER) {
owner = Optional.empty();
}
ConnectorViewDefinition definition = new ConnectorViewDefinition(sql, session.getCatalog(), session.getSchema(), columns, owner, !owner.isPresent());
metadata.createView(session, name, definition, statement.isReplace());
return immediateFuture(null);
}
use of io.prestosql.sql.analyzer.Analysis in project boostkit-bigdata by kunpengcompute.
the class OmniLocalQueryRunner method createPlan.
public Plan createPlan(Session session, @Language("SQL") String sql, List<PlanOptimizer> optimizers, LogicalPlanner.Stage stage, WarningCollector warningCollector) {
PreparedQuery preparedQuery = new QueryPreparer(sqlParser).prepareQuery(session, sql);
assertFormattedSql(sqlParser, createParsingOptions(session), preparedQuery.getStatement());
PlanNodeIdAllocator idAllocator = new PlanNodeIdAllocator();
QueryExplainer queryExplainer = new QueryExplainer(optimizers, planFragmenter, metadata, accessControl, sqlParser, statsCalculator, costCalculator, dataDefinitionTask, heuristicIndexerManager, cubeManager);
Analyzer analyzer = new Analyzer(session, metadata, sqlParser, accessControl, Optional.of(queryExplainer), preparedQuery.getParameters(), warningCollector, heuristicIndexerManager, cubeManager);
LogicalPlanner logicalPlanner = new LogicalPlanner(session, optimizers, new PlanSanityChecker(true), idAllocator, metadata, new TypeAnalyzer(sqlParser, metadata), statsCalculator, costCalculator, warningCollector);
Analysis analysis = analyzer.analyze(preparedQuery.getStatement());
return logicalPlanner.plan(analysis, false, stage);
}
use of io.prestosql.sql.analyzer.Analysis in project hetu-core by openlookeng.
the class LogicalPlanner method createVacuumTablePlan.
private RelationPlan createVacuumTablePlan(Analysis analysis, VacuumTable vacuumTable) {
TableHandle handle = analysis.getTableHandle(vacuumTable.getTable());
TableMetadata tableMetadata = metadata.getTableMetadata(session, handle);
List<ColumnMetadata> columns = tableMetadata.getColumns();
List<String> columnNames = columns.stream().filter(column -> !column.isHidden()).map(ColumnMetadata::getName).collect(Collectors.toList());
List<Symbol> symbols = columns.stream().filter(column -> !column.isHidden()).map(c -> planSymbolAllocator.newSymbol(c.getName(), c.getType())).collect(Collectors.toList());
ColumnHandle rowIdHandle = metadata.getDeleteRowIdColumnHandle(session, handle);
ColumnMetadata rowIdColumnMetadata = metadata.getColumnMetadata(session, handle, rowIdHandle);
Type rowIdType = rowIdColumnMetadata.getType();
Symbol rowIdSymbol = planSymbolAllocator.newSymbol("$rowId", rowIdType);
symbols.add(rowIdSymbol);
columnNames.add(rowIdHandle.getColumnName());
String catalogName = handle.getCatalogName().getCatalogName();
TableStatisticsMetadata statisticsMetadata = TableStatisticsMetadata.empty();
return createVacuumWriterPlan(analysis, handle, vacuumTable, new VacuumTargetReference(handle, vacuumTable.isFull(), vacuumTable.isUnify(), vacuumTable.getPartition()), symbols, columnNames, statisticsMetadata);
}
use of io.prestosql.sql.analyzer.Analysis in project hetu-core by openlookeng.
the class LogicalPlanner method createUpdatePlan.
private RelationPlan createUpdatePlan(Analysis analysis, Update node) {
TableHandle handle = analysis.getTableHandle(node.getTable());
if (handle.getConnectorHandle().isUpdateAsInsertSupported()) {
QueryPlanner.UpdateDeleteRelationPlan updatePlan = new QueryPlanner(analysis, planSymbolAllocator, idAllocator, buildLambdaDeclarationToSymbolMap(analysis, planSymbolAllocator), metadata, session, namedSubPlan, uniqueIdAllocator).planUpdateRowAsInsert(node);
RelationPlan plan = updatePlan.getPlan();
Analysis.Update update = analysis.getUpdate().get();
TableMetadata tableMetadata = metadata.getTableMetadata(session, update.getTarget());
Optional<NewTableLayout> newTableLayout = metadata.getUpdateLayout(session, update.getTarget());
String catalogName = update.getTarget().getCatalogName().getCatalogName();
TableStatisticsMetadata statisticsMetadata = metadata.getStatisticsCollectionMetadataForWrite(session, catalogName, tableMetadata.getMetadata());
Optional<Expression> constraint = updatePlan.getPredicate().isPresent() ? Optional.of(OriginalExpressionUtils.castToExpression(updatePlan.getPredicate().get())) : Optional.empty();
return createTableWriterPlan(analysis, plan, new TableWriterNode.UpdateReference(update.getTarget(), constraint, updatePlan.getColumnAssignments()), updatePlan.getColumNames(), newTableLayout, statisticsMetadata);
}
UpdateNode updateNode = new QueryPlanner(analysis, planSymbolAllocator, idAllocator, buildLambdaDeclarationToSymbolMap(analysis, planSymbolAllocator), metadata, session, namedSubPlan, uniqueIdAllocator).plan(node);
TableFinishNode commitNode = new TableFinishNode(idAllocator.getNextId(), updateNode, updateNode.getTarget(), planSymbolAllocator.newSymbol("rows", BIGINT), Optional.empty(), Optional.empty());
return new RelationPlan(commitNode, analysis.getScope(node), commitNode.getOutputSymbols());
}
use of io.prestosql.sql.analyzer.Analysis in project hetu-core by openlookeng.
the class QueryPlanner method plan.
public UpdateNode plan(Update node) {
Table table = node.getTable();
TableHandle handle = analysis.getTableHandle(table);
TableMetadata tableMetadata = metadata.getTableMetadata(session, handle);
List<ColumnMetadata> dataColumns = tableMetadata.getMetadata().getColumns().stream().filter(column -> !column.isHidden()).collect(toImmutableList());
List<String> targetColumnNames = node.getAssignmentItems().stream().map(assignment -> assignment.getName().toString()).collect(toImmutableList());
// Create lists of columnnames and SET expressions, in table column order
ImmutableList.Builder<String> updatedColumnNamesBuilder = ImmutableList.builder();
ImmutableList.Builder<Type> updatedColumnTypesBuilder = ImmutableList.builder();
ImmutableList.Builder<Expression> orderedColumnValuesBuilder = ImmutableList.builder();
ImmutableMap.Builder<String, Expression> setExpressions = new ImmutableMap.Builder<>();
for (ColumnMetadata columnMetadata : dataColumns) {
String name = columnMetadata.getName();
Type type = columnMetadata.getType();
int index = targetColumnNames.indexOf(name);
if (index >= 0) {
updatedColumnNamesBuilder.add(name);
updatedColumnTypesBuilder.add(type);
orderedColumnValuesBuilder.add(node.getAssignmentItems().get(index).getValue());
setExpressions.put(name, node.getAssignmentItems().get(index).getValue());
}
}
List<String> updatedColumnNames = updatedColumnNamesBuilder.build();
List<Type> updatedColumnTypes = updatedColumnTypesBuilder.build();
List<Expression> orderedColumnValues = orderedColumnValuesBuilder.build();
// create table scan
RelationPlan relationPlan = new RelationPlanner(analysis, planSymbolAllocator, idAllocator, lambdaDeclarationToSymbolMap, metadata, session, namedSubPlan, uniqueIdAllocator).process(table, null);
PlanBuilder builder = planBuilderFor(relationPlan);
if (node.getWhere().isPresent()) {
builder = filter(builder, node.getWhere().get(), node);
}
builder = builder.appendProjections(orderedColumnValues, planSymbolAllocator, idAllocator);
PlanAndMappings planAndMappings = coerce(builder, orderedColumnValues, analysis, idAllocator, planSymbolAllocator, typeCoercion);
builder = planAndMappings.getSubPlan();
ImmutableList.Builder<Symbol> updatedColumnValuesBuilder = ImmutableList.builder();
orderedColumnValues.forEach(columnValue -> updatedColumnValuesBuilder.add(planAndMappings.get(columnValue)));
Symbol rowId = builder.translate(analysis.getRowIdField(table));
updatedColumnValuesBuilder.add(rowId);
List<Symbol> outputs = ImmutableList.of(planSymbolAllocator.newSymbol("partialrows", BIGINT), planSymbolAllocator.newSymbol("fragment", VARBINARY));
Optional<PlanNodeId> tableScanId = getIdForLeftTableScan(relationPlan.getRoot());
checkArgument(tableScanId.isPresent(), "tableScanId not present");
// create update node
return new UpdateNode(idAllocator.getNextId(), builder.getRoot(), new TableWriterNode.UpdateTarget(handle, metadata.getTableMetadata(session, handle).getTable(), updatedColumnNames, updatedColumnTypes), rowId, updatedColumnValuesBuilder.build(), outputs, setExpressions.build());
}
Aggregations