use of com.facebook.presto.spi.ConnectorSession in project presto by prestodb.
the class AbstractTestHiveClientS3 method testGetRecordsS3.
@Test
public void testGetRecordsS3() throws Exception {
try (Transaction transaction = newTransaction()) {
ConnectorMetadata metadata = transaction.getMetadata();
ConnectorSession session = newSession();
ConnectorTableHandle table = getTableHandle(metadata, tableS3);
List<ColumnHandle> columnHandles = ImmutableList.copyOf(metadata.getColumnHandles(session, table).values());
Map<String, Integer> columnIndex = indexColumns(columnHandles);
List<ConnectorTableLayoutResult> tableLayoutResults = metadata.getTableLayouts(session, table, new Constraint<>(TupleDomain.all(), bindings -> true), Optional.empty());
HiveTableLayoutHandle layoutHandle = (HiveTableLayoutHandle) getOnlyElement(tableLayoutResults).getTableLayout().getHandle();
assertEquals(layoutHandle.getPartitions().get().size(), 1);
ConnectorSplitSource splitSource = splitManager.getSplits(transaction.getTransactionHandle(), session, layoutHandle);
long sum = 0;
for (ConnectorSplit split : getAllSplits(splitSource)) {
try (ConnectorPageSource pageSource = pageSourceProvider.createPageSource(transaction.getTransactionHandle(), session, split, columnHandles)) {
MaterializedResult result = materializeSourceDataStream(session, pageSource, getTypes(columnHandles));
for (MaterializedRow row : result) {
sum += (Long) row.getField(columnIndex.get("t_bigint"));
}
}
}
assertEquals(sum, 78300);
}
}
use of com.facebook.presto.spi.ConnectorSession in project presto by prestodb.
the class SplitManager method getSplits.
public SplitSource getSplits(Session session, TableLayoutHandle layout) {
ConnectorId connectorId = layout.getConnectorId();
ConnectorSplitManager splitManager = getConnectorSplitManager(connectorId);
ConnectorSession connectorSession = session.toConnectorSession(connectorId);
ConnectorSplitSource source = splitManager.getSplits(layout.getTransactionHandle(), connectorSession, layout.getConnectorHandle());
SplitSource splitSource = new ConnectorAwareSplitSource(connectorId, layout.getTransactionHandle(), source);
if (minScheduleSplitBatchSize > 1) {
splitSource = new BufferingSplitSource(splitSource, minScheduleSplitBatchSize);
}
return splitSource;
}
use of com.facebook.presto.spi.ConnectorSession in project presto by prestodb.
the class ExpressionInterpreter method invoke.
public static Object invoke(ConnectorSession session, ScalarFunctionImplementation function, List<Object> argumentValues) {
MethodHandle handle = function.getMethodHandle();
if (function.getInstanceFactory().isPresent()) {
try {
handle = handle.bindTo(function.getInstanceFactory().get().invoke());
} catch (Throwable throwable) {
if (throwable instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
throw Throwables.propagate(throwable);
}
}
if (handle.type().parameterCount() > 0 && handle.type().parameterType(0) == ConnectorSession.class) {
handle = handle.bindTo(session);
}
try {
List<Object> actualArguments = new ArrayList<>();
Class<?>[] parameterArray = handle.type().parameterArray();
for (int i = 0; i < argumentValues.size(); i++) {
Object argument = argumentValues.get(i);
if (function.getNullFlags().get(i)) {
boolean isNull = argument == null;
if (isNull) {
argument = Defaults.defaultValue(parameterArray[actualArguments.size()]);
}
actualArguments.add(argument);
actualArguments.add(isNull);
} else {
actualArguments.add(argument);
}
}
return handle.invokeWithArguments(actualArguments);
} catch (Throwable throwable) {
if (throwable instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
throw Throwables.propagate(throwable);
}
}
use of com.facebook.presto.spi.ConnectorSession in project presto by prestodb.
the class HiveMetadata method beginInsert.
@Override
public HiveInsertTableHandle beginInsert(ConnectorSession session, ConnectorTableHandle tableHandle) {
verifyJvmTimeZone();
SchemaTableName tableName = schemaTableName(tableHandle);
Optional<Table> table = metastore.getTable(tableName.getSchemaName(), tableName.getTableName());
if (!table.isPresent()) {
throw new TableNotFoundException(tableName);
}
checkTableIsWritable(table.get());
for (Column column : table.get().getDataColumns()) {
if (!isWritableType(column.getType())) {
throw new PrestoException(NOT_SUPPORTED, format("Inserting into Hive table %s.%s with column type %s not supported", table.get().getDatabaseName(), table.get().getTableName(), column.getType()));
}
}
List<HiveColumnHandle> handles = hiveColumnHandles(connectorId, table.get()).stream().filter(columnHandle -> !columnHandle.isHidden()).collect(toList());
HiveStorageFormat tableStorageFormat = extractHiveStorageFormat(table.get());
LocationHandle locationHandle = locationService.forExistingTable(metastore, session.getUser(), session.getQueryId(), table.get());
HiveInsertTableHandle result = new HiveInsertTableHandle(connectorId, tableName.getSchemaName(), tableName.getTableName(), handles, session.getQueryId(), metastore.generatePageSinkMetadata(tableName), locationHandle, table.get().getStorage().getBucketProperty(), tableStorageFormat, respectTableFormat ? tableStorageFormat : defaultStorageFormat);
Optional<Path> writePathRoot = locationService.writePathRoot(locationHandle);
Path targetPathRoot = locationService.targetPathRoot(locationHandle);
if (writePathRoot.isPresent()) {
WriteMode mode = writePathRoot.get().equals(targetPathRoot) ? DIRECT_TO_TARGET_NEW_DIRECTORY : STAGE_AND_MOVE_TO_TARGET_DIRECTORY;
metastore.declareIntentionToWrite(session, mode, writePathRoot.get(), result.getFilePrefix(), tableName);
} else {
metastore.declareIntentionToWrite(session, DIRECT_TO_TARGET_EXISTING_DIRECTORY, targetPathRoot, result.getFilePrefix(), tableName);
}
return result;
}
use of com.facebook.presto.spi.ConnectorSession in project presto by prestodb.
the class InformationSchemaSplitManager method getSplits.
@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorTableLayoutHandle layout) {
InformationSchemaTableLayoutHandle handle = (InformationSchemaTableLayoutHandle) layout;
Map<ColumnHandle, NullableValue> bindings = extractFixedValues(handle.getConstraint()).orElse(ImmutableMap.of());
List<HostAddress> localAddress = ImmutableList.of(nodeManager.getCurrentNode().getHostAndPort());
Map<String, NullableValue> filters = bindings.entrySet().stream().collect(toMap(entry -> ((InformationSchemaColumnHandle) entry.getKey()).getColumnName(), Entry::getValue));
ConnectorSplit split = new InformationSchemaSplit(handle.getTable(), filters, localAddress);
return new FixedSplitSource(ImmutableList.of(split));
}
Aggregations