Java Code Examples for com.facebook.presto.spi.ConnectorTableMetadata#getColumns()
The following examples show how to use
com.facebook.presto.spi.ConnectorTableMetadata#getColumns() .
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: ParaflowMetaDataReader.java From paraflow with Apache License 2.0 | 6 votes |
public void createTable(ConnectorSession session, ConnectorTableMetadata tableMetadata) { List<ColumnMetadata> columns = tableMetadata.getColumns(); List<String> columnName = new LinkedList<>(); List<String> dataType = new LinkedList<>(); for (ColumnMetadata column : columns) { columnName.add(column.getName()); dataType.add(column.getType().getDisplayName()); } String tblName = tableMetadata.getTable().getTableName(); String dbName = tableMetadata.getTable().getSchemaName(); // createTable metaClient.createTable(dbName, tblName, session.getUser(), "", -1, "", -1, columnName, dataType); }
Example 2
Source File: NativeKuduClientSession.java From presto-kudu with Apache License 2.0 | 6 votes |
@Override public KuduTable createTable(ConnectorTableMetadata tableMetadata, boolean ignoreExisting) { try { SchemaTableName schemeTableName= tableMetadata.getTable(); String rawName = toRawName(schemeTableName); if (ignoreExisting) { if (client.tableExists(rawName)) { return null; } } if(!schemaExists(schemeTableName.getSchemaName())){ throw new SchemaNotFoundException(schemeTableName.getSchemaName()); } List<ColumnMetadata> columns = tableMetadata.getColumns(); Map<String, Object> properties = tableMetadata.getProperties(); Schema schema = buildSchema(columns, properties); CreateTableOptions options = buildCreateTableOptions(schema, properties); return client.createTable(rawName, schema, options); } catch (KuduException e) { throw new PrestoException(GENERIC_INTERNAL_ERROR, e); } }
Example 3
Source File: HbaseClient.java From presto-connectors with Apache License 2.0 | 5 votes |
private static void validateLocalityGroups(ConnectorTableMetadata meta) { // Validate any configured locality groups Optional<Map<String, Set<String>>> groups = HbaseTableProperties.getLocalityGroups(meta.getProperties()); if (!groups.isPresent()) { return; } String rowIdColumn = getRowIdColumn(meta); // For each locality group for (Map.Entry<String, Set<String>> g : groups.get().entrySet()) { if (g.getValue().contains(rowIdColumn)) { throw new PrestoException(INVALID_TABLE_PROPERTY, "Row ID column cannot be in a locality group"); } // Validate the specified column names exist in the table definition, // incrementing a counter for each matching column int matchingColumns = 0; for (ColumnMetadata column : meta.getColumns()) { if (g.getValue().contains(column.getName().toLowerCase(Locale.ENGLISH))) { ++matchingColumns; // Break out early if all columns are found if (matchingColumns == g.getValue().size()) { break; } } } // If the number of matched columns does not equal the defined size, // then a column was specified that does not exist // (or there is a duplicate column in the table DDL, which is also an issue but has been checked before in validateColumns). if (matchingColumns != g.getValue().size()) { throw new PrestoException(INVALID_TABLE_PROPERTY, "Unknown Presto column defined for locality group " + g.getKey()); } } }
Example 4
Source File: HbaseClient.java From presto-connectors with Apache License 2.0 | 4 votes |
private static void validateColumns(ConnectorTableMetadata meta) { // Check all the column types, and throw an exception if the types of a map are complex // While it is a rare case, this is not supported by the Hbase connector ImmutableSet.Builder<String> columnNameBuilder = ImmutableSet.builder(); for (ColumnMetadata column : meta.getColumns()) { if (Types.isMapType(column.getType())) { if (Types.isMapType(Types.getKeyType(column.getType())) || Types.isMapType(Types.getValueType(column.getType())) || Types.isArrayType(Types.getKeyType(column.getType())) || Types.isArrayType(Types.getValueType(column.getType()))) { throw new PrestoException(INVALID_TABLE_PROPERTY, "Key/value types of a MAP column must be plain types"); } } columnNameBuilder.add(column.getName().toLowerCase(Locale.ENGLISH)); } // Validate the columns are distinct if (columnNameBuilder.build().size() != meta.getColumns().size()) { throw new PrestoException(INVALID_TABLE_PROPERTY, "Duplicate column names are not supported"); } Optional<Map<String, Pair<String, String>>> columnMapping = HbaseTableProperties.getColumnMapping(meta.getProperties()); if (columnMapping.isPresent()) { // Validate there are no duplicates in the column mapping long distinctMappings = columnMapping.get().values().stream().distinct().count(); if (distinctMappings != columnMapping.get().size()) { throw new PrestoException(INVALID_TABLE_PROPERTY, "Duplicate column family/qualifier pair detected in column mapping, check the value of " + HbaseTableProperties.COLUMN_MAPPING); } // Validate no column is mapped to the reserved entry String reservedRowIdColumn = HbasePageSink.ROW_ID_COLUMN.toString(); if (columnMapping.get().values().stream() .filter(pair -> pair.getKey().equals(reservedRowIdColumn) && pair.getValue().equals(reservedRowIdColumn)) .count() > 0) { throw new PrestoException(INVALID_TABLE_PROPERTY, format("Column familiy/qualifier mapping of %s:%s is reserved", reservedRowIdColumn, reservedRowIdColumn)); } } else if (HbaseTableProperties.isExternal(meta.getProperties())) { // Column mapping is not defined (i.e. use column generation) and table is external // But column generation is for internal tables only throw new PrestoException(INVALID_TABLE_PROPERTY, "Column generation for external tables is not supported, must specify " + HbaseTableProperties.COLUMN_MAPPING); } }
Example 5
Source File: TestKinesisTableDescriptionSupplier.java From presto-kinesis with Apache License 2.0 | 4 votes |
@Test public void testRelatedObjects() { // Metadata has a handle to the supplier, ensure it can use it correctly KinesisMetadata meta = injector.getInstance(KinesisMetadata.class); assertNotNull(meta); Map<SchemaTableName, KinesisStreamDescription> tblMap = meta.getDefinedTables(); SchemaTableName tblName = new SchemaTableName("prod", "test_table"); KinesisStreamDescription desc = tblMap.get(tblName); assertNotNull(desc); assertEquals(desc.getSchemaName(), "prod"); assertEquals(desc.getTableName(), "test_table"); assertEquals(desc.getStreamName(), "test_kinesis_stream"); List<String> schemas = meta.listSchemaNames(null); assertEquals(schemas.size(), 1); assertEquals(schemas.get(0), "prod"); KinesisTableHandle tblHandle = meta.getTableHandle(null, tblName); assertNotNull(tblHandle); assertEquals(tblHandle.getSchemaName(), "prod"); assertEquals(tblHandle.getTableName(), "test_table"); assertEquals(tblHandle.getStreamName(), "test_kinesis_stream"); assertEquals(tblHandle.getMessageDataFormat(), "json"); ConnectorTableMetadata tblMeta = meta.getTableMetadata(null, tblHandle); assertNotNull(tblMeta); assertEquals(tblMeta.getTable().getSchemaName(), "prod"); assertEquals(tblMeta.getTable().getTableName(), "test_table"); List<ColumnMetadata> columnList = tblMeta.getColumns(); assertNotNull(columnList); boolean foundServiceType = false; boolean foundPartitionKey = false; for (ColumnMetadata column : columnList) { if (column.getName().equals("service_type")) { foundServiceType = true; assertEquals(column.getType().getDisplayName(), "varchar(20)"); } if (column.getName().equals("_partition_key")) { foundPartitionKey = true; assertEquals(column.getType().getDisplayName(), "varchar"); } } assertTrue(foundServiceType); assertTrue(foundPartitionKey); }