public ExpressionOptimizer(FunctionRegistry registry, TypeManager typeManager, Session session) { this.registry = registry; this.typeManager = typeManager; this.session = session.toConnectorSession(); }
private OptionalDouble doubleValueFromLiteral(Type type, Literal literal) { Object literalValue = LiteralInterpreter.evaluate(metadata, session.toConnectorSession(), literal); return toStatsRepresentation(metadata, session, type, literalValue); } }
public List<ConnectorPartitionHandle> listPartitionHandles( Session session, PartitioningHandle partitioningHandle) { ConnectorNodePartitioningProvider partitioningProvider = partitioningProviders.get(partitioningHandle.getConnectorId().get()); return partitioningProvider.listPartitionHandles( partitioningHandle.getTransactionHandle().orElse(null), session.toConnectorSession(), partitioningHandle.getConnectorHandle()); }
public ConnectorId getConnectorId(Session session, QualifiedObjectName table) { if (table.getSchemaName().equals(INFORMATION_SCHEMA_NAME)) { return informationSchemaId; } if (systemTables.getTableHandle(session.toConnectorSession(systemTablesId), table.asSchemaTableName()) != null) { return systemTablesId; } return connectorId; }
private static Object toTypeObjectValue(Session session, Type type, Object value) { BlockBuilder blockBuilder = type.createBlockBuilder(null, 1); writeNativeValue(type, blockBuilder, value); return type.getObjectValue(session.toConnectorSession(), blockBuilder, 0); } }
@Override public void renameColumn(Session session, TableHandle tableHandle, ColumnHandle source, String target) { ConnectorId connectorId = tableHandle.getConnectorId(); ConnectorMetadata metadata = getMetadataForWrite(session, connectorId); metadata.renameColumn(session.toConnectorSession(connectorId), tableHandle.getConnectorHandle(), source, target.toLowerCase(ENGLISH)); }
@Override public Optional<ConnectorOutputMetadata> finishCreateTable(Session session, OutputTableHandle tableHandle, Collection<Slice> fragments, Collection<ComputedStatistics> computedStatistics) { ConnectorId connectorId = tableHandle.getConnectorId(); ConnectorMetadata metadata = getMetadata(session, connectorId); return metadata.finishCreateTable(session.toConnectorSession(connectorId), tableHandle.getConnectorHandle(), fragments, computedStatistics); }
@Override public Optional<ConnectorOutputMetadata> finishInsert(Session session, InsertTableHandle tableHandle, Collection<Slice> fragments, Collection<ComputedStatistics> computedStatistics) { ConnectorId connectorId = tableHandle.getConnectorId(); ConnectorMetadata metadata = getMetadata(session, connectorId); return metadata.finishInsert(session.toConnectorSession(connectorId), tableHandle.getConnectorHandle(), fragments, computedStatistics); }
@Override public void beginQuery(Session session, Set<ConnectorId> connectors) { for (ConnectorId connectorId : connectors) { ConnectorMetadata metadata = getMetadata(session, connectorId); ConnectorSession connectorSession = session.toConnectorSession(connectorId); metadata.beginQuery(connectorSession); registerCatalogForQueryId(session.getQueryId(), metadata); } }
@Override public void finishDelete(Session session, TableHandle tableHandle, Collection<Slice> fragments) { ConnectorId connectorId = tableHandle.getConnectorId(); ConnectorMetadata metadata = getMetadata(session, connectorId); metadata.finishDelete(session.toConnectorSession(connectorId), tableHandle.getConnectorHandle(), fragments); }
@Override public Optional<NewTableLayout> getNewTableLayout(Session session, String catalogName, ConnectorTableMetadata tableMetadata) { CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, catalogName); ConnectorId connectorId = catalogMetadata.getConnectorId(); ConnectorMetadata metadata = catalogMetadata.getMetadata(); ConnectorTransactionHandle transactionHandle = catalogMetadata.getTransactionHandleFor(connectorId); ConnectorSession connectorSession = session.toConnectorSession(connectorId); return metadata.getNewTableLayout(connectorSession, tableMetadata) .map(layout -> new NewTableLayout(connectorId, transactionHandle, layout)); }
@Override public OutputTableHandle beginCreateTable(Session session, String catalogName, ConnectorTableMetadata tableMetadata, Optional<NewTableLayout> layout) { CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, catalogName); ConnectorId connectorId = catalogMetadata.getConnectorId(); ConnectorMetadata metadata = catalogMetadata.getMetadata(); ConnectorTransactionHandle transactionHandle = catalogMetadata.getTransactionHandleFor(connectorId); ConnectorSession connectorSession = session.toConnectorSession(connectorId); ConnectorOutputTableHandle handle = metadata.beginCreateTable(connectorSession, tableMetadata, layout.map(NewTableLayout::getLayout)); return new OutputTableHandle(connectorId, transactionHandle, handle); }
@Override public TableMetadata getTableMetadata(Session session, TableHandle tableHandle) { ConnectorId connectorId = tableHandle.getConnectorId(); ConnectorMetadata metadata = getMetadata(session, connectorId); ConnectorTableMetadata tableMetadata = metadata.getTableMetadata(session.toConnectorSession(connectorId), tableHandle.getConnectorHandle()); if (tableMetadata.getColumns().isEmpty()) { throw new PrestoException(NOT_SUPPORTED, "Table has no columns: " + tableHandle); } return new TableMetadata(connectorId, tableMetadata); }
@Override public ConnectorPageSink createPageSink(Session session, OutputTableHandle tableHandle) { // assumes connectorId and catalog are the same ConnectorSession connectorSession = session.toConnectorSession(tableHandle.getConnectorId()); return providerFor(tableHandle.getConnectorId()).createPageSink(tableHandle.getTransactionHandle(), connectorSession, tableHandle.getConnectorHandle()); }
@Override public Optional<Object> getInfo(Session session, TableLayoutHandle handle) { ConnectorId connectorId = handle.getConnectorId(); ConnectorMetadata metadata = getMetadata(session, connectorId); ConnectorTableLayout tableLayout = metadata.getTableLayout(session.toConnectorSession(connectorId), handle.getConnectorHandle()); return metadata.getInfo(tableLayout.getHandle()); }
@Override public void createSchema(Session session, CatalogSchemaName schema, Map<String, Object> properties) { CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, schema.getCatalogName()); ConnectorId connectorId = catalogMetadata.getConnectorId(); ConnectorMetadata metadata = catalogMetadata.getMetadata(); metadata.createSchema(session.toConnectorSession(connectorId), schema.getSchemaName(), properties); }
@Override public void renameSchema(Session session, CatalogSchemaName source, String target) { CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, source.getCatalogName()); ConnectorId connectorId = catalogMetadata.getConnectorId(); ConnectorMetadata metadata = catalogMetadata.getMetadata(); metadata.renameSchema(session.toConnectorSession(connectorId), source.getSchemaName(), target); }
@Override public void dropSchema(Session session, CatalogSchemaName schema) { CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, schema.getCatalogName()); ConnectorId connectorId = catalogMetadata.getConnectorId(); ConnectorMetadata metadata = catalogMetadata.getMetadata(); metadata.dropSchema(session.toConnectorSession(connectorId), schema.getSchemaName()); }
private int compareOriginalValueToCoerced(Type originalValueType, Object originalValue, Type coercedValueType, Object coercedValue) { Signature castToOriginalTypeOperator = metadata.getFunctionRegistry().getCoercion(coercedValueType, originalValueType); Object coercedValueInOriginalType = functionInvoker.invoke(castToOriginalTypeOperator, session.toConnectorSession(), coercedValue); Block originalValueBlock = Utils.nativeValueToBlock(originalValueType, originalValue); Block coercedValueBlock = Utils.nativeValueToBlock(originalValueType, coercedValueInOriginalType); return originalValueType.compareTo(originalValueBlock, 0, coercedValueBlock, 0); }
@Override public void renameTable(Session session, TableHandle tableHandle, QualifiedObjectName newTableName) { String catalogName = newTableName.getCatalogName(); CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, catalogName); ConnectorId connectorId = catalogMetadata.getConnectorId(); if (!tableHandle.getConnectorId().equals(connectorId)) { throw new PrestoException(SYNTAX_ERROR, "Cannot rename tables across catalogs"); } ConnectorMetadata metadata = catalogMetadata.getMetadata(); metadata.renameTable(session.toConnectorSession(connectorId), tableHandle.getConnectorHandle(), newTableName.asSchemaTableName()); }