use of com.facebook.presto.spi.TableHandle in project presto by prestodb.
the class AbstractTestHiveClient method readTable.
private MaterializedResult readTable(Transaction transaction, ConnectorTableHandle hiveTableHandle, ConnectorTableLayoutHandle hiveTableLayoutHandle, List<ColumnHandle> columnHandles, ConnectorSession session, OptionalInt expectedSplitCount, Optional<HiveStorageFormat> expectedStorageFormat) throws Exception {
List<ConnectorSplit> splits = getAllSplits(session, transaction, hiveTableLayoutHandle);
if (expectedSplitCount.isPresent()) {
assertEquals(splits.size(), expectedSplitCount.getAsInt());
}
TableHandle tableHandle = toTableHandle(transaction, hiveTableHandle, hiveTableLayoutHandle);
ImmutableList.Builder<MaterializedRow> allRows = ImmutableList.builder();
for (ConnectorSplit split : splits) {
try (ConnectorPageSource pageSource = pageSourceProvider.createPageSource(transaction.getTransactionHandle(), session, split, tableHandle.getLayout().get(), columnHandles, NON_CACHEABLE)) {
expectedStorageFormat.ifPresent(format -> assertPageSourceType(pageSource, format));
MaterializedResult result = materializeSourceDataStream(session, pageSource, getTypes(columnHandles));
allRows.addAll(result.getMaterializedRows());
}
}
return new MaterializedResult(allRows.build(), getTypes(columnHandles));
}
use of com.facebook.presto.spi.TableHandle in project presto by prestodb.
the class TestHiveIntegrationSmokeTest method getHiveTableProperty.
private Object getHiveTableProperty(String tableName, Function<HiveTableLayoutHandle, Object> propertyGetter) {
Session session = getSession();
Metadata metadata = ((DistributedQueryRunner) getQueryRunner()).getCoordinator().getMetadata();
return transaction(getQueryRunner().getTransactionManager(), getQueryRunner().getAccessControl()).readOnly().execute(session, transactionSession -> {
Optional<TableHandle> tableHandle = metadata.getTableHandle(transactionSession, new QualifiedObjectName(catalog, TPCH_SCHEMA, tableName));
assertTrue(tableHandle.isPresent());
TableLayout layout = metadata.getLayout(transactionSession, tableHandle.get(), Constraint.alwaysTrue(), Optional.empty()).getLayout();
return propertyGetter.apply((HiveTableLayoutHandle) layout.getNewTableHandle().getLayout().get());
});
}
use of com.facebook.presto.spi.TableHandle in project presto by prestodb.
the class TestHiveIntegrationSmokeTest method getHiveInsertTableHandle.
private HiveInsertTableHandle getHiveInsertTableHandle(Session session, String tableName) {
Metadata metadata = ((DistributedQueryRunner) getQueryRunner()).getCoordinator().getMetadata();
return transaction(getQueryRunner().getTransactionManager(), getQueryRunner().getAccessControl()).execute(session, transactionSession -> {
QualifiedObjectName objectName = new QualifiedObjectName(catalog, TPCH_SCHEMA, tableName);
Optional<TableHandle> handle = metadata.getTableHandle(transactionSession, objectName);
InsertTableHandle insertTableHandle = metadata.beginInsert(transactionSession, handle.get());
HiveInsertTableHandle hiveInsertTableHandle = (HiveInsertTableHandle) insertTableHandle.getConnectorHandle();
metadata.finishInsert(transactionSession, insertTableHandle, ImmutableList.of(), ImmutableList.of());
return hiveInsertTableHandle;
});
}
use of com.facebook.presto.spi.TableHandle in project presto by prestodb.
the class QueryPlanner method plan.
public DeleteNode plan(Delete node) {
RelationType descriptor = analysis.getOutputDescriptor(node.getTable());
TableHandle handle = analysis.getTableHandle(node.getTable());
ColumnHandle rowIdHandle = metadata.getUpdateRowIdColumnHandle(session, handle);
Type rowIdType = metadata.getColumnMetadata(session, handle, rowIdHandle).getType();
// add table columns
ImmutableList.Builder<VariableReferenceExpression> outputVariablesBuilder = ImmutableList.builder();
ImmutableMap.Builder<VariableReferenceExpression, ColumnHandle> columns = ImmutableMap.builder();
ImmutableList.Builder<Field> fields = ImmutableList.builder();
for (Field field : descriptor.getAllFields()) {
VariableReferenceExpression variable = variableAllocator.newVariable(getSourceLocation(field.getNodeLocation()), field.getName().get(), field.getType());
outputVariablesBuilder.add(variable);
columns.put(variable, analysis.getColumn(field));
fields.add(field);
}
// add rowId column
Field rowIdField = Field.newUnqualified(node.getLocation(), Optional.empty(), rowIdType);
VariableReferenceExpression rowIdVariable = variableAllocator.newVariable(getSourceLocation(node), "$rowId", rowIdField.getType());
outputVariablesBuilder.add(rowIdVariable);
columns.put(rowIdVariable, rowIdHandle);
fields.add(rowIdField);
// create table scan
List<VariableReferenceExpression> outputVariables = outputVariablesBuilder.build();
PlanNode tableScan = new TableScanNode(getSourceLocation(node), idAllocator.getNextId(), handle, outputVariables, columns.build(), TupleDomain.all(), TupleDomain.all());
Scope scope = Scope.builder().withRelationType(RelationId.anonymous(), new RelationType(fields.build())).build();
RelationPlan relationPlan = new RelationPlan(tableScan, scope, outputVariables);
TranslationMap translations = new TranslationMap(relationPlan, analysis, lambdaDeclarationToVariableMap);
translations.setFieldMappings(relationPlan.getFieldMappings());
PlanBuilder builder = new PlanBuilder(translations, relationPlan.getRoot());
if (node.getWhere().isPresent()) {
builder = filter(builder, node.getWhere().get(), node);
}
// create delete node
VariableReferenceExpression rowId = new VariableReferenceExpression(Optional.empty(), builder.translate(new FieldReference(relationPlan.getDescriptor().indexOf(rowIdField))).getName(), rowIdField.getType());
List<VariableReferenceExpression> deleteNodeOutputVariables = ImmutableList.of(variableAllocator.newVariable("partialrows", BIGINT), variableAllocator.newVariable("fragment", VARBINARY));
return new DeleteNode(getSourceLocation(node), idAllocator.getNextId(), builder.getRoot(), rowId, deleteNodeOutputVariables);
}
use of com.facebook.presto.spi.TableHandle in project presto by prestodb.
the class RelationPlanner method visitTable.
@Override
protected RelationPlan visitTable(Table node, Void context) {
Query namedQuery = analysis.getNamedQuery(node);
Scope scope = analysis.getScope(node);
if (namedQuery != null) {
RelationPlan subPlan = process(namedQuery, null);
// Add implicit coercions if view query produces types that don't match the declared output types
// of the view (e.g., if the underlying tables referenced by the view changed)
Type[] types = scope.getRelationType().getAllFields().stream().map(Field::getType).toArray(Type[]::new);
RelationPlan withCoercions = addCoercions(subPlan, types);
return new RelationPlan(withCoercions.getRoot(), scope, withCoercions.getFieldMappings());
}
TableHandle handle = analysis.getTableHandle(node);
ImmutableList.Builder<VariableReferenceExpression> outputVariablesBuilder = ImmutableList.builder();
ImmutableMap.Builder<VariableReferenceExpression, ColumnHandle> columns = ImmutableMap.builder();
for (Field field : scope.getRelationType().getAllFields()) {
VariableReferenceExpression variable = variableAllocator.newVariable(getSourceLocation(node), field.getName().get(), field.getType());
outputVariablesBuilder.add(variable);
columns.put(variable, analysis.getColumn(field));
}
List<VariableReferenceExpression> outputVariables = outputVariablesBuilder.build();
PlanNode root = new TableScanNode(getSourceLocation(node.getLocation()), idAllocator.getNextId(), handle, outputVariables, columns.build(), TupleDomain.all(), TupleDomain.all());
return new RelationPlan(root, scope, outputVariables);
}
Aggregations