use of io.prestosql.sql.tree.VacuumTable in project hetu-core by openlookeng.
the class AstBuilder method visitVacuumTable.
@Override
public Node visitVacuumTable(SqlBaseParser.VacuumTableContext context) {
boolean isFull = context.FULL() != null;
boolean isMerge = context.UNIFY() != null;
// Exclude single quotes
Optional<String> partition = getTextIfPresent(context.partition).map(s -> {
if (s.startsWith("'") && s.endsWith("'")) {
return Optional.of(s.substring(1, s.length() - 1));
}
return Optional.of(s);
}).orElse(Optional.empty());
boolean isAsync = context.AND_WAIT() == null;
return new VacuumTable(Optional.of(getLocation(context)), new Table(getLocation(context), getQualifiedName(context.qualifiedName())), isFull, isMerge, partition, isAsync);
}
use of io.prestosql.sql.tree.VacuumTable 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.tree.VacuumTable in project hetu-core by openlookeng.
the class TestSqlParser method testVacuum.
@Test
public void testVacuum() {
assertStatement("VACUUM TABLE t", new VacuumTable(Optional.empty(), table(QualifiedName.of("t")), false, false, Optional.empty(), true));
assertStatement("VACUUM TABLE t AND WAIT", new VacuumTable(Optional.empty(), table(QualifiedName.of("t")), false, false, Optional.empty(), false));
assertStatement("VACUUM TABLE t FULL AND WAIT", new VacuumTable(Optional.empty(), table(QualifiedName.of("t")), true, false, Optional.empty(), false));
assertStatement("VACUUM TABLE t FULL UNIFY AND WAIT", new VacuumTable(Optional.empty(), table(QualifiedName.of("t")), true, true, Optional.empty(), false));
assertStatement("VACUUM TABLE t PARTITION 'age = 10' AND WAIT", new VacuumTable(Optional.empty(), table(QualifiedName.of("t")), false, false, Optional.of("age = 10"), false));
}
Aggregations