io.prestosql.spi.connector.ColumnMetadata Java Examples
The following examples show how to use
io.prestosql.spi.connector.ColumnMetadata.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestTypeConversions.java From presto with Apache License 2.0 | 6 votes |
@Test public void testConvertTwoLevelsRecordColumn() { BigQueryColumnHandle column = new BigQueryColumnHandle("rec", BigQueryType.RECORD, Field.Mode.NULLABLE, ImmutableList.of( new BigQueryColumnHandle("sub_rec", BigQueryType.RECORD, Field.Mode.NULLABLE, ImmutableList.of( new BigQueryColumnHandle("sub_sub_s", BigQueryType.STRING, Field.Mode.NULLABLE, ImmutableList.of(), null), new BigQueryColumnHandle("sub_sub_i", BigQueryType.INTEGER, Field.Mode.NULLABLE, ImmutableList.of(), null) ), null), new BigQueryColumnHandle("sub_s", BigQueryType.STRING, Field.Mode.NULLABLE, ImmutableList.of(), null), new BigQueryColumnHandle("sub_i", BigQueryType.INTEGER, Field.Mode.NULLABLE, ImmutableList.of(), null) ), null); ColumnMetadata metadata = column.getColumnMetadata(); RowType targetType = RowType.rowType( RowType.field("sub_rec", RowType.rowType( RowType.field("sub_sub_s", VarcharType.VARCHAR), RowType.field("sub_sub_i", BigintType.BIGINT))), RowType.field("sub_s", VarcharType.VARCHAR), RowType.field("sub_i", BigintType.BIGINT)); assertThat(metadata.getType()).isEqualTo(targetType); }
Example #2
Source File: ElasticsearchMetadata.java From presto with Apache License 2.0 | 6 votes |
private List<ColumnMetadata> makeColumnMetadata(List<IndexMetadata.Field> fields) { ImmutableList.Builder<ColumnMetadata> result = ImmutableList.builder(); for (BuiltinColumns builtinColumn : BuiltinColumns.values()) { result.add(builtinColumn.getMetadata()); } for (IndexMetadata.Field field : fields) { result.add(ColumnMetadata.builder() .setName(field.getName()) .setType(toPrestoType(field)) .build()); } return result.build(); }
Example #3
Source File: PulsarMetadata.java From pulsar with Apache License 2.0 | 6 votes |
/** * Convert pulsar schema into presto table metadata. */ static List<ColumnMetadata> getPulsarColumns(TopicName topicName, SchemaInfo schemaInfo, boolean withInternalColumns, PulsarColumnHandle.HandleKeyValueType handleKeyValueType) { SchemaType schemaType = schemaInfo.getType(); if (schemaType.isStruct()) { return getPulsarColumnsFromStructSchema(topicName, schemaInfo, withInternalColumns, handleKeyValueType); } else if (schemaType.isPrimitive()) { return getPulsarColumnsFromPrimitiveSchema(topicName, schemaInfo, withInternalColumns, handleKeyValueType); } else if (schemaType.equals(SchemaType.KEY_VALUE)) { return getPulsarColumnsFromKeyValueSchema(topicName, schemaInfo, withInternalColumns); } else { throw new IllegalArgumentException("Unsupported schema : " + schemaInfo); } }
Example #4
Source File: TestRaptorConnector.java From presto with Apache License 2.0 | 6 votes |
private long createTable(String name) { ConnectorTransactionHandle transaction = connector.beginTransaction(READ_COMMITTED, false); connector.getMetadata(transaction).createTable( SESSION, new ConnectorTableMetadata( new SchemaTableName("test", name), ImmutableList.of(new ColumnMetadata("id", BIGINT))), false); connector.commit(transaction); transaction = connector.beginTransaction(READ_COMMITTED, false); ConnectorTableHandle tableHandle = getTableHandle(connector.getMetadata(transaction), name); connector.commit(transaction); return ((RaptorTableHandle) tableHandle).getTableId(); }
Example #5
Source File: TestPrometheusIntegrationTests2.java From presto with Apache License 2.0 | 6 votes |
@Test(dependsOnMethods = "testRetrieveUpValue") public void testGetTableMetadata() throws Exception { PrometheusMetadata metadata = new PrometheusMetadata(client); // known table ConnectorTableMetadata tableMetadata = metadata.getTableMetadata(SESSION, RUNTIME_DETERMINED_TABLE_HANDLE); assertEquals(tableMetadata.getTable(), new SchemaTableName("default", "up")); assertEquals(tableMetadata.getColumns(), ImmutableList.of( new ColumnMetadata("labels", varcharMapType), new ColumnMetadata("timestamp", TimestampType.TIMESTAMP), new ColumnMetadata("value", DOUBLE))); // unknown tables should produce null assertNull(metadata.getTableMetadata(SESSION, new PrometheusTableHandle("unknown", "unknown"))); assertNull(metadata.getTableMetadata(SESSION, new PrometheusTableHandle("default", "unknown"))); assertNull(metadata.getTableMetadata(SESSION, new PrometheusTableHandle("unknown", "numbers"))); }
Example #6
Source File: SystemPageSourceProvider.java From presto with Apache License 2.0 | 6 votes |
private static RecordSet toRecordSet(ConnectorTransactionHandle sourceTransaction, SystemTable table, ConnectorSession session, TupleDomain<Integer> constraint) { return new RecordSet() { private final List<Type> types = table.getTableMetadata().getColumns().stream() .map(ColumnMetadata::getType) .collect(toImmutableList()); @Override public List<Type> getColumnTypes() { return types; } @Override public RecordCursor cursor() { return table.cursor(sourceTransaction, session, constraint); } }; }
Example #7
Source File: KuduMetadata.java From presto with Apache License 2.0 | 6 votes |
@Override public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) { requireNonNull(prefix, "SchemaTablePrefix is null"); List<SchemaTableName> tables; if (prefix.getTable().isEmpty()) { tables = listTables(session, prefix.getSchema()); } else { tables = ImmutableList.of(prefix.toSchemaTableName()); } ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> columns = ImmutableMap.builder(); for (SchemaTableName tableName : tables) { KuduTableHandle tableHandle = getTableHandle(session, tableName); if (tableHandle != null) { ConnectorTableMetadata tableMetadata = getTableMetadata(tableHandle); columns.put(tableName, tableMetadata.getColumns()); } } return columns.build(); }
Example #8
Source File: BaseJdbcClient.java From presto with Apache License 2.0 | 6 votes |
@Override public void addColumn(ConnectorSession session, JdbcTableHandle handle, ColumnMetadata column) { try (Connection connection = connectionFactory.openConnection(JdbcIdentity.from(session))) { String columnName = column.getName(); if (connection.getMetaData().storesUpperCaseIdentifiers()) { columnName = columnName.toUpperCase(ENGLISH); } String sql = format( "ALTER TABLE %s ADD %s", quoted(handle.getCatalogName(), handle.getSchemaName(), handle.getTableName()), getColumnSql(session, column, columnName)); execute(connection, sql); } catch (SQLException e) { throw new PrestoException(JDBC_ERROR, e); } }
Example #9
Source File: HBaseTable.java From presto-hbase-connector with Apache License 2.0 | 6 votes |
public HBaseTable(String schemaName, HTableDescriptor tabDesc, HBaseConfig config) { this.hTableDescriptor = Objects.requireNonNull(tabDesc, "tabDesc is null"); Objects.requireNonNull(schemaName, "schemaName is null"); ImmutableList<ColumnMetadata> tableMeta = null; try { String tableName = tabDesc.getNameAsString() != null && tabDesc.getNameAsString().contains(":") ? tabDesc.getNameAsString().split(":")[1] : tabDesc.getNameAsString(); tableMeta = Utils.getColumnMetaFromJson(schemaName, tableName, config.getMetaDir()); if (tableMeta == null || tableMeta.size() <= 0) { logger.error("OOPS! Table meta info cannot be NULL, table name=" + tabDesc.getNameAsString()); throw new Exception("Cannot find meta info of table " + tabDesc.getNameAsString() + "."); } } catch (Exception e) { logger.error(e, e.getMessage()); } this.columnsMetadata = tableMeta; }
Example #10
Source File: ManifestsTable.java From presto with Apache License 2.0 | 6 votes |
public ManifestsTable(SchemaTableName tableName, Table icebergTable, Optional<Long> snapshotId) { this.icebergTable = requireNonNull(icebergTable, "icebergTable is null"); tableMetadata = new ConnectorTableMetadata( tableName, ImmutableList.<ColumnMetadata>builder() .add(new ColumnMetadata("path", VARCHAR)) .add(new ColumnMetadata("length", BIGINT)) .add(new ColumnMetadata("partition_spec_id", INTEGER)) .add(new ColumnMetadata("added_snapshot_id", BIGINT)) .add(new ColumnMetadata("added_data_files_count", INTEGER)) .add(new ColumnMetadata("existing_data_files_count", INTEGER)) .add(new ColumnMetadata("deleted_data_files_count", INTEGER)) .add(new ColumnMetadata("partitions", RowType.rowType( RowType.field("contains_null", BOOLEAN), RowType.field("lower_bound", VARCHAR), RowType.field("upper_bound", VARCHAR)))) .build()); this.snapshotId = requireNonNull(snapshotId, "snapshotId is null"); }
Example #11
Source File: MockConnectorFactory.java From presto with Apache License 2.0 | 6 votes |
private MockConnector( ConnectorContext context, Function<ConnectorSession, List<String>> listSchemaNames, BiFunction<ConnectorSession, String, List<SchemaTableName>> listTables, BiFunction<ConnectorSession, SchemaTablePrefix, Map<SchemaTableName, ConnectorViewDefinition>> getViews, BiFunction<ConnectorSession, SchemaTableName, ConnectorTableHandle> getTableHandle, Function<SchemaTableName, List<ColumnMetadata>> getColumns, ApplyProjection applyProjection, BiFunction<ConnectorSession, SchemaTableName, Optional<ConnectorNewTableLayout>> getInsertLayout, BiFunction<ConnectorSession, ConnectorTableMetadata, Optional<ConnectorNewTableLayout>> getNewTableLayout, Supplier<Iterable<EventListener>> eventListeners, ListRoleGrants roleGrants) { this.context = requireNonNull(context, "context is null"); this.listSchemaNames = requireNonNull(listSchemaNames, "listSchemaNames is null"); this.listTables = requireNonNull(listTables, "listTables is null"); this.getViews = requireNonNull(getViews, "getViews is null"); this.getTableHandle = requireNonNull(getTableHandle, "getTableHandle is null"); this.getColumns = requireNonNull(getColumns, "getColumns is null"); this.applyProjection = requireNonNull(applyProjection, "applyProjection is null"); this.getInsertLayout = requireNonNull(getInsertLayout, "getInsertLayout is null"); this.getNewTableLayout = requireNonNull(getNewTableLayout, "getNewTableLayout is null"); this.eventListeners = requireNonNull(eventListeners, "eventListeners is null"); this.roleGrants = requireNonNull(roleGrants, "roleGrants is null"); }
Example #12
Source File: RedisMetadata.java From presto with Apache License 2.0 | 6 votes |
@Nullable private ConnectorTableMetadata getTableMetadata(SchemaTableName schemaTableName) { RedisTableDescription table = getDefinedTables().get(schemaTableName); if (table == null) { return null; } ImmutableList.Builder<ColumnMetadata> builder = ImmutableList.builder(); appendFields(builder, table.getKey()); appendFields(builder, table.getValue()); for (RedisInternalFieldDescription fieldDescription : RedisInternalFieldDescription.values()) { builder.add(fieldDescription.getColumnMetadata(hideInternalColumns)); } return new ConnectorTableMetadata(schemaTableName, builder.build()); }
Example #13
Source File: TestRaptorMetadata.java From presto with Apache License 2.0 | 6 votes |
private static void assertTableEqual(ConnectorTableMetadata actual, ConnectorTableMetadata expected) { assertEquals(actual.getTable(), expected.getTable()); List<ColumnMetadata> actualColumns = actual.getColumns().stream() .filter(columnMetadata -> !columnMetadata.isHidden()) .collect(Collectors.toList()); List<ColumnMetadata> expectedColumns = expected.getColumns(); assertEquals(actualColumns.size(), expectedColumns.size()); for (int i = 0; i < actualColumns.size(); i++) { ColumnMetadata actualColumn = actualColumns.get(i); ColumnMetadata expectedColumn = expectedColumns.get(i); assertEquals(actualColumn.getName(), expectedColumn.getName()); assertEquals(actualColumn.getType(), expectedColumn.getType()); } assertEquals(actual.getProperties(), expected.getProperties()); }
Example #14
Source File: TestJdbcMetadata.java From presto with Apache License 2.0 | 5 votes |
@Test public void testCreateAndAlterTable() { SchemaTableName table = new SchemaTableName("example", "foo"); metadata.createTable(SESSION, new ConnectorTableMetadata(table, ImmutableList.of(new ColumnMetadata("text", VARCHAR))), false); JdbcTableHandle handle = metadata.getTableHandle(SESSION, table); ConnectorTableMetadata layout = metadata.getTableMetadata(SESSION, handle); assertEquals(layout.getTable(), table); assertEquals(layout.getColumns().size(), 1); assertEquals(layout.getColumns().get(0), new ColumnMetadata("text", VARCHAR)); metadata.addColumn(SESSION, handle, new ColumnMetadata("x", VARCHAR)); layout = metadata.getTableMetadata(SESSION, handle); assertEquals(layout.getColumns().size(), 2); assertEquals(layout.getColumns().get(0), new ColumnMetadata("text", VARCHAR)); assertEquals(layout.getColumns().get(1), new ColumnMetadata("x", VARCHAR)); JdbcColumnHandle columnHandle = new JdbcColumnHandle("x", JDBC_VARCHAR, VARCHAR); metadata.dropColumn(SESSION, handle, columnHandle); layout = metadata.getTableMetadata(SESSION, handle); assertEquals(layout.getColumns().size(), 1); assertEquals(layout.getColumns().get(0), new ColumnMetadata("text", VARCHAR)); SchemaTableName newTableName = new SchemaTableName("example", "bar"); metadata.renameTable(SESSION, handle, newTableName); handle = metadata.getTableHandle(SESSION, newTableName); layout = metadata.getTableMetadata(SESSION, handle); assertEquals(layout.getTable(), newTableName); assertEquals(layout.getColumns().size(), 1); assertEquals(layout.getColumns().get(0), new ColumnMetadata("text", VARCHAR)); }
Example #15
Source File: MockConnectorFactory.java From presto with Apache License 2.0 | 5 votes |
@Override public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session, ConnectorTableHandle tableHandle) { MockConnectorTableHandle table = (MockConnectorTableHandle) tableHandle; return getColumns.apply(table.getTableName()).stream() .collect(toImmutableMap(ColumnMetadata::getName, column -> new TpchColumnHandle(column.getName(), column.getType()))); }
Example #16
Source File: RaptorMetadata.java From presto with Apache License 2.0 | 5 votes |
private static ColumnMetadata hiddenColumn(String name, Type type) { return ColumnMetadata.builder() .setName(name) .setType(type) .setHidden(true) .build(); }
Example #17
Source File: KinesisStreamFieldDescription.java From presto with Apache License 2.0 | 5 votes |
ColumnMetadata getColumnMetadata() { return ColumnMetadata.builder() .setName(getName()) .setType(getType()) .setComment(Optional.ofNullable(getComment())) .setHidden(isHidden()) .build(); }
Example #18
Source File: RaptorMetadata.java From presto with Apache License 2.0 | 5 votes |
@Override public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) { requireNonNull(prefix, "prefix is null"); ImmutableListMultimap.Builder<SchemaTableName, ColumnMetadata> columns = ImmutableListMultimap.builder(); for (TableColumn tableColumn : dao.listTableColumns(prefix.getSchema().orElse(null), prefix.getTable().orElse(null))) { ColumnMetadata columnMetadata = new ColumnMetadata(tableColumn.getColumnName(), tableColumn.getDataType()); columns.put(tableColumn.getTable(), columnMetadata); } return Multimaps.asMap(columns.build()); }
Example #19
Source File: ClassLoaderSafeConnectorMetadata.java From presto with Apache License 2.0 | 5 votes |
@Override public void addColumn(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnMetadata column) { try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(classLoader)) { delegate.addColumn(session, tableHandle, column); } }
Example #20
Source File: TestJdbcMetadata.java From presto with Apache License 2.0 | 5 votes |
@Test public void getColumnMetadata() { assertEquals( metadata.getColumnMetadata(SESSION, tableHandle, new JdbcColumnHandle("text", JDBC_VARCHAR, VARCHAR)), new ColumnMetadata("text", VARCHAR)); }
Example #21
Source File: PulsarMetadata.java From pulsar with Apache License 2.0 | 5 votes |
@Override public ColumnMetadata getColumnMetadata(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnHandle columnHandle) { convertTableHandle(tableHandle); return convertColumnHandle(columnHandle).getColumnMetadata(); }
Example #22
Source File: PinotMetadata.java From presto with Apache License 2.0 | 5 votes |
private static ColumnMetadata createPinotColumnMetadata(PinotColumn pinotColumn) { return ColumnMetadata.builder() .setName(pinotColumn.getName().toLowerCase(ENGLISH)) .setType(pinotColumn.getType()) .setProperties(ImmutableMap.<String, Object>builder() .put(PINOT_COLUMN_NAME_PROPERTY, pinotColumn.getName()) .build()) .build(); }
Example #23
Source File: PhoenixMetadata.java From presto with Apache License 2.0 | 5 votes |
private ConnectorTableMetadata getTableMetadata(ConnectorSession session, ConnectorTableHandle table, boolean rowkeyRequired) { JdbcTableHandle handle = (JdbcTableHandle) table; List<ColumnMetadata> columnMetadata = phoenixClient.getColumns(session, handle).stream() .filter(column -> rowkeyRequired || !ROWKEY.equalsIgnoreCase(column.getColumnName())) .map(JdbcColumnHandle::getColumnMetadata) .collect(toImmutableList()); return new ConnectorTableMetadata(handle.getSchemaTableName(), columnMetadata, getTableProperties(session, handle)); }
Example #24
Source File: ElasticsearchMetadata.java From presto with Apache License 2.0 | 5 votes |
public InternalTableMetadata( SchemaTableName tableName, List<ColumnMetadata> columnMetadata, Map<String, ColumnHandle> columnHandles) { this.tableName = tableName; this.columnMetadata = columnMetadata; this.columnHandles = columnHandles; }
Example #25
Source File: AccumuloMetadata.java From presto with Apache License 2.0 | 5 votes |
@Override public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) { requireNonNull(prefix, "prefix is null"); ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> columns = ImmutableMap.builder(); for (SchemaTableName tableName : listTables(session, prefix)) { ConnectorTableMetadata tableMetadata = getTableMetadata(tableName); // table can disappear during listing operation if (tableMetadata != null) { columns.put(tableName, tableMetadata.getColumns()); } } return columns.build(); }
Example #26
Source File: AccumuloColumnHandle.java From presto with Apache License 2.0 | 5 votes |
@JsonIgnore public ColumnMetadata getColumnMetadata() { return ColumnMetadata.builder() .setName(name) .setType(type) .setComment(Optional.ofNullable(comment)) .build(); }
Example #27
Source File: PinotMetadata.java From presto with Apache License 2.0 | 5 votes |
private List<ColumnMetadata> getColumnsMetadata(String tableName) { List<PinotColumn> columns = getPinotColumns(tableName); return columns.stream() .map(PinotMetadata::createPinotColumnMetadata) .collect(toImmutableList()); }
Example #28
Source File: KuduMetadata.java From presto with Apache License 2.0 | 5 votes |
private ConnectorTableMetadata getTableMetadata(KuduTableHandle tableHandle) { KuduTable table = tableHandle.getTable(clientSession); Schema schema = table.getSchema(); List<ColumnMetadata> columnsMetaList = schema.getColumns().stream() .filter(column -> !column.isKey() || !column.getName().equals(KuduColumnHandle.ROW_ID)) .map(this::getColumnMetadata) .collect(toImmutableList()); Map<String, Object> properties = clientSession.getTableProperties(tableHandle); return new ConnectorTableMetadata(tableHandle.getSchemaTableName(), columnsMetaList, properties); }
Example #29
Source File: TestTypeConversions.java From presto with Apache License 2.0 | 5 votes |
@Test public void testConvertStringArrayColumn() { BigQueryColumnHandle column = new BigQueryColumnHandle("test", BigQueryType.STRING, Field.Mode.REPEATED, ImmutableList.of(), null); ColumnMetadata metadata = column.getColumnMetadata(); assertThat(metadata.getType()).isEqualTo(new ArrayType(VarcharType.VARCHAR)); }
Example #30
Source File: TestTypeConversions.java From presto with Apache License 2.0 | 5 votes |
@Test public void testConvertOneLevelRecordColumn() { BigQueryColumnHandle column = new BigQueryColumnHandle("rec", BigQueryType.RECORD, Field.Mode.NULLABLE, ImmutableList.of( new BigQueryColumnHandle("sub_s", BigQueryType.STRING, Field.Mode.NULLABLE, ImmutableList.of(), null), new BigQueryColumnHandle("sub_i", BigQueryType.INTEGER, Field.Mode.NULLABLE, ImmutableList.of(), null) ), null); ColumnMetadata metadata = column.getColumnMetadata(); RowType targetType = RowType.rowType( RowType.field("sub_s", VarcharType.VARCHAR), RowType.field("sub_i", BigintType.BIGINT)); assertThat(metadata.getType()).isEqualTo(targetType); }