List of usage examples for com.google.common.collect Maps uniqueIndex
public static <K, V> ImmutableMap<K, V> uniqueIndex(Iterator<V> values, Function<? super V, K> keyFunction)
From source file:io.prestosql.plugin.hive.HiveMetadata.java
@Override public HiveOutputTableHandle beginCreateTable(ConnectorSession session, ConnectorTableMetadata tableMetadata, Optional<ConnectorNewTableLayout> layout) { verifyJvmTimeZone();/*from www. j a v a2 s. c om*/ if (getExternalLocation(tableMetadata.getProperties()) != null) { throw new PrestoException(NOT_SUPPORTED, "External tables cannot be created using CREATE TABLE AS"); } if (getAvroSchemaUrl(tableMetadata.getProperties()) != null) { throw new PrestoException(NOT_SUPPORTED, "CREATE TABLE AS not supported when Avro schema url is set"); } HiveStorageFormat tableStorageFormat = getHiveStorageFormat(tableMetadata.getProperties()); List<String> partitionedBy = getPartitionedBy(tableMetadata.getProperties()); Optional<HiveBucketProperty> bucketProperty = getBucketProperty(tableMetadata.getProperties()); // get the root directory for the database SchemaTableName schemaTableName = tableMetadata.getTable(); String schemaName = schemaTableName.getSchemaName(); String tableName = schemaTableName.getTableName(); Map<String, String> tableProperties = getEmptyTableProperties(tableMetadata, !partitionedBy.isEmpty(), new HdfsContext(session, schemaName, tableName)); List<HiveColumnHandle> columnHandles = getColumnHandles(tableMetadata, ImmutableSet.copyOf(partitionedBy), typeTranslator); HiveStorageFormat partitionStorageFormat = isRespectTableFormat(session) ? tableStorageFormat : getHiveStorageFormat(session); // unpartitioned tables ignore the partition storage format HiveStorageFormat actualStorageFormat = partitionedBy.isEmpty() ? tableStorageFormat : partitionStorageFormat; actualStorageFormat.validateColumns(columnHandles); Map<String, HiveColumnHandle> columnHandlesByName = Maps.uniqueIndex(columnHandles, HiveColumnHandle::getName); List<Column> partitionColumns = partitionedBy.stream().map(columnHandlesByName::get) .map(column -> new Column(column.getName(), column.getHiveType(), column.getComment())) .collect(toList()); checkPartitionTypesSupported(partitionColumns); LocationHandle locationHandle = locationService.forNewTable(metastore, session, schemaName, tableName); HiveOutputTableHandle result = new HiveOutputTableHandle(schemaName, tableName, columnHandles, session.getQueryId(), metastore.generatePageSinkMetadata(schemaTableName), locationHandle, tableStorageFormat, partitionStorageFormat, partitionedBy, bucketProperty, session.getUser(), tableProperties); WriteInfo writeInfo = locationService.getQueryWriteInfo(locationHandle); metastore.declareIntentionToWrite(session, writeInfo.getWriteMode(), writeInfo.getWritePath(), result.getFilePrefix(), schemaTableName); return result; }
From source file:org.glowroot.central.repo.ConfigRepositoryImpl.java
private static Map<String, PluginProperty> buildMutablePropertiesMap(List<PluginProperty> properties) { return Maps.newHashMap(Maps.uniqueIndex(properties, PluginProperty::getName)); }
From source file:com.facebook.presto.tests.AbstractTestQueries.java
@Test public void testShowSession() throws Exception { MaterializedResult result = computeActual(getSession().withSystemProperty("test_string", "foo string") .withSystemProperty("test_long", "424242") .withCatalogProperty("connector", "connector_string", "bar string") .withCatalogProperty("connector", "connector_long", "11"), "SHOW SESSION"); ImmutableMap<String, MaterializedRow> properties = Maps.uniqueIndex(result.getMaterializedRows(), input -> { assertEquals(input.getFieldCount(), 5); return (String) input.getField(0); });// w w w.j a va 2s .com assertEquals(properties.get("test_string"), new MaterializedRow(1, "test_string", "foo string", "test default", "varchar", "test string property")); assertEquals(properties.get("test_long"), new MaterializedRow(1, "test_long", "424242", "42", "bigint", "test long property")); assertEquals(properties.get("connector.connector_string"), new MaterializedRow(1, "connector.connector_string", "bar string", "connector default", "varchar", "connector string property")); assertEquals(properties.get("connector.connector_long"), new MaterializedRow(1, "connector.connector_long", "11", "33", "bigint", "connector long property")); }
From source file:io.prestosql.tests.AbstractTestQueries.java
@Test public void testShowSession() { Session session = new Session(getSession().getQueryId(), Optional.empty(), getSession().isClientTransactionSupport(), getSession().getIdentity(), getSession().getSource(), getSession().getCatalog(), getSession().getSchema(), getSession().getPath(), getSession().getTraceToken(), getSession().getTimeZoneKey(), getSession().getLocale(), getSession().getRemoteUserAddress(), getSession().getUserAgent(), getSession().getClientInfo(), getSession().getClientTags(), getSession().getClientCapabilities(), getSession().getResourceEstimates(), getSession().getStartTime(), ImmutableMap.<String, String>builder().put("test_string", "foo string").put("test_long", "424242") .build(),// w ww . j a v a2 s .com ImmutableMap.of(), ImmutableMap.of(TESTING_CATALOG, ImmutableMap.<String, String>builder().put("connector_string", "bar string") .put("connector_long", "11").build()), getQueryRunner().getMetadata().getSessionPropertyManager(), getSession().getPreparedStatements()); MaterializedResult result = computeActual(session, "SHOW SESSION"); ImmutableMap<String, MaterializedRow> properties = Maps.uniqueIndex(result.getMaterializedRows(), input -> { assertEquals(input.getFieldCount(), 5); return (String) input.getField(0); }); assertEquals(properties.get("test_string"), new MaterializedRow(1, "test_string", "foo string", "test default", "varchar", "test string property")); assertEquals(properties.get("test_long"), new MaterializedRow(1, "test_long", "424242", "42", "bigint", "test long property")); assertEquals(properties.get(TESTING_CATALOG + ".connector_string"), new MaterializedRow(1, TESTING_CATALOG + ".connector_string", "bar string", "connector default", "varchar", "connector string property")); assertEquals(properties.get(TESTING_CATALOG + ".connector_long"), new MaterializedRow(1, TESTING_CATALOG + ".connector_long", "11", "33", "bigint", "connector long property")); }