Search in sources :

Example 6 with ExtendedHiveMetastore

use of com.facebook.presto.hive.metastore.ExtendedHiveMetastore in project presto by prestodb.

the class AbstractTestHiveClient method setup.

protected final void setup(String host, int port, String databaseName, String timeZone) {
    HiveClientConfig hiveClientConfig = getHiveClientConfig();
    CacheConfig cacheConfig = getCacheConfig();
    MetastoreClientConfig metastoreClientConfig = getMetastoreClientConfig();
    hiveClientConfig.setTimeZone(timeZone);
    String proxy = System.getProperty("hive.metastore.thrift.client.socks-proxy");
    if (proxy != null) {
        metastoreClientConfig.setMetastoreSocksProxy(HostAndPort.fromString(proxy));
    }
    HiveCluster hiveCluster = new TestingHiveCluster(metastoreClientConfig, host, port);
    ExtendedHiveMetastore metastore = new CachingHiveMetastore(new BridgingHiveMetastore(new ThriftHiveMetastore(hiveCluster, metastoreClientConfig), new HivePartitionMutator()), executor, false, Duration.valueOf("1m"), Duration.valueOf("15s"), 10000, false, MetastoreCacheScope.ALL, 0.0);
    setup(databaseName, hiveClientConfig, cacheConfig, metastoreClientConfig, metastore);
}
Also used : TestingHiveCluster(com.facebook.presto.hive.metastore.thrift.TestingHiveCluster) CachingHiveMetastore(com.facebook.presto.hive.metastore.CachingHiveMetastore) ThriftHiveMetastore(com.facebook.presto.hive.metastore.thrift.ThriftHiveMetastore) ExtendedHiveMetastore(com.facebook.presto.hive.metastore.ExtendedHiveMetastore) CacheConfig(com.facebook.presto.cache.CacheConfig) HiveCluster(com.facebook.presto.hive.metastore.thrift.HiveCluster) TestingHiveCluster(com.facebook.presto.hive.metastore.thrift.TestingHiveCluster) HivePartitionMutator(com.facebook.presto.hive.metastore.HivePartitionMutator) BridgingHiveMetastore(com.facebook.presto.hive.metastore.thrift.BridgingHiveMetastore)

Example 7 with ExtendedHiveMetastore

use of com.facebook.presto.hive.metastore.ExtendedHiveMetastore in project presto by prestodb.

the class HiveBenchmarkQueryRunner method createLocalQueryRunner.

public static LocalQueryRunner createLocalQueryRunner(File tempDir) {
    Session session = testSessionBuilder().setCatalog("hive").setSchema("tpch").build();
    LocalQueryRunner localQueryRunner = new LocalQueryRunner(session);
    // add tpch
    localQueryRunner.createCatalog("tpch", new TpchConnectorFactory(1), ImmutableMap.of());
    // add hive
    File hiveDir = new File(tempDir, "hive_data");
    ExtendedHiveMetastore metastore = createTestingFileHiveMetastore(hiveDir);
    metastore.createDatabase(METASTORE_CONTEXT, Database.builder().setDatabaseName("tpch").setOwnerName("public").setOwnerType(PrincipalType.ROLE).build());
    HiveConnectorFactory hiveConnectorFactory = new HiveConnectorFactory("hive", HiveBenchmarkQueryRunner.class.getClassLoader(), Optional.of(metastore));
    Map<String, String> hiveCatalogConfig = ImmutableMap.<String, String>builder().put("hive.max-split-size", "10GB").build();
    localQueryRunner.createCatalog("hive", hiveConnectorFactory, hiveCatalogConfig);
    localQueryRunner.execute("CREATE TABLE orders AS SELECT * FROM tpch.sf1.orders");
    localQueryRunner.execute("CREATE TABLE lineitem AS SELECT * FROM tpch.sf1.lineitem");
    return localQueryRunner;
}
Also used : TpchConnectorFactory(com.facebook.presto.tpch.TpchConnectorFactory) ExtendedHiveMetastore(com.facebook.presto.hive.metastore.ExtendedHiveMetastore) File(java.io.File) LocalQueryRunner(com.facebook.presto.testing.LocalQueryRunner) Session(com.facebook.presto.Session)

Example 8 with ExtendedHiveMetastore

use of com.facebook.presto.hive.metastore.ExtendedHiveMetastore in project presto by prestodb.

the class AbstractTestHiveClientLocal method initialize.

@BeforeClass
public void initialize() {
    tempDir = Files.createTempDir();
    ExtendedHiveMetastore metastore = createMetastore(tempDir);
    metastore.createDatabase(METASTORE_CONTEXT, Database.builder().setDatabaseName(testDbName).setOwnerName("public").setOwnerType(PrincipalType.ROLE).build());
    HiveClientConfig hiveConfig = new HiveClientConfig().setTimeZone("America/Los_Angeles");
    MetastoreClientConfig metastoreClientConfig = new MetastoreClientConfig();
    setup(testDbName, hiveConfig, new CacheConfig(), metastoreClientConfig, metastore);
}
Also used : ExtendedHiveMetastore(com.facebook.presto.hive.metastore.ExtendedHiveMetastore) CacheConfig(com.facebook.presto.cache.CacheConfig) BeforeClass(org.testng.annotations.BeforeClass)

Example 9 with ExtendedHiveMetastore

use of com.facebook.presto.hive.metastore.ExtendedHiveMetastore in project presto by prestodb.

the class TestHiveLogicalPlanner method testMetadataAggregationFoldingWithEmptyPartitionsAndMetastoreThreshold.

@Test
public void testMetadataAggregationFoldingWithEmptyPartitionsAndMetastoreThreshold() {
    QueryRunner queryRunner = getQueryRunner();
    Session optimizeMetadataQueriesWithHighThreshold = Session.builder(this.getQueryRunner().getDefaultSession()).setSystemProperty(OPTIMIZE_METADATA_QUERIES, Boolean.toString(true)).setSystemProperty(OPTIMIZE_METADATA_QUERIES_CALL_THRESHOLD, Integer.toString(100)).build();
    Session optimizeMetadataQueriesWithLowThreshold = Session.builder(this.getQueryRunner().getDefaultSession()).setSystemProperty(OPTIMIZE_METADATA_QUERIES, Boolean.toString(true)).setSystemProperty(OPTIMIZE_METADATA_QUERIES_CALL_THRESHOLD, Integer.toString(1)).build();
    Session optimizeMetadataQueriesIgnoreStatsWithLowThreshold = Session.builder(this.getQueryRunner().getDefaultSession()).setSystemProperty(OPTIMIZE_METADATA_QUERIES_IGNORE_STATS, Boolean.toString(true)).setSystemProperty(OPTIMIZE_METADATA_QUERIES_CALL_THRESHOLD, Integer.toString(1)).build();
    Session shufflePartitionColumns = Session.builder(this.getQueryRunner().getDefaultSession()).setCatalogSessionProperty(HIVE_CATALOG, SHUFFLE_PARTITIONED_COLUMNS_FOR_TABLE_WRITE, Boolean.toString(true)).build();
    queryRunner.execute(shufflePartitionColumns, "CREATE TABLE test_metadata_aggregation_folding_with_empty_partitions_with_threshold WITH (partitioned_by = ARRAY['ds']) AS " + "SELECT orderkey, CAST(to_iso8601(date_add('DAY', orderkey % 2, date('2020-07-01'))) AS VARCHAR) AS ds FROM orders WHERE orderkey < 1000");
    ExtendedHiveMetastore metastore = replicateHiveMetastore((DistributedQueryRunner) queryRunner);
    MetastoreContext metastoreContext = new MetastoreContext(getSession().getUser(), getSession().getQueryId().getId(), Optional.empty(), Optional.empty(), Optional.empty(), false, HiveColumnConverterProvider.DEFAULT_COLUMN_CONVERTER_PROVIDER);
    Table table = metastore.getTable(metastoreContext, getSession().getSchema().get(), "test_metadata_aggregation_folding_with_empty_partitions_with_threshold").get();
    // Add one partition with no statistics.
    String partitionNameNoStats = "ds=2020-07-20";
    Partition partitionNoStats = createDummyPartition(table, partitionNameNoStats);
    metastore.addPartitions(metastoreContext, table.getDatabaseName(), table.getTableName(), ImmutableList.of(new PartitionWithStatistics(partitionNoStats, partitionNameNoStats, PartitionStatistics.empty())));
    // Add one partition with statistics indicating that it has no rows.
    String emptyPartitionName = "ds=2020-06-30";
    Partition emptyPartition = createDummyPartition(table, emptyPartitionName);
    metastore.addPartitions(metastoreContext, table.getDatabaseName(), table.getTableName(), ImmutableList.of(new PartitionWithStatistics(emptyPartition, emptyPartitionName, PartitionStatistics.builder().setBasicStatistics(new HiveBasicStatistics(1, 0, 0, 0)).build())));
    try {
        // Test the non-reducible code path.
        // Enable rewrite as all matching partitions have stats.
        assertPlan(optimizeMetadataQueriesWithHighThreshold, "SELECT DISTINCT ds FROM test_metadata_aggregation_folding_with_empty_partitions_with_threshold WHERE ds BETWEEN '2020-07-01' AND '2020-07-03'", anyTree(values(ImmutableList.of("ds"), ImmutableList.of(ImmutableList.of(new StringLiteral("2020-07-01")), ImmutableList.of(new StringLiteral("2020-07-02"))))));
        // All matching partitions have stats, Metastore threshold is reached, Disable rewrite
        assertPlan(optimizeMetadataQueriesWithLowThreshold, "SELECT DISTINCT ds FROM test_metadata_aggregation_folding_with_empty_partitions_with_threshold WHERE ds BETWEEN '2020-07-01' AND '2020-07-03'", anyTree(tableScanWithConstraint("test_metadata_aggregation_folding_with_empty_partitions_with_threshold", ImmutableMap.of("ds", multipleValues(VARCHAR, utf8Slices("2020-07-01", "2020-07-02"))))));
        // All matching partitions have stats, Metastore threshold is reached, but IgnoreStats will overwrite, Enable rewrite
        assertPlan(optimizeMetadataQueriesIgnoreStatsWithLowThreshold, "SELECT DISTINCT ds FROM test_metadata_aggregation_folding_with_empty_partitions_with_threshold WHERE ds BETWEEN '2020-07-01' AND '2020-07-03'", anyTree(values(ImmutableList.of("ds"), ImmutableList.of(ImmutableList.of(new StringLiteral("2020-07-01")), ImmutableList.of(new StringLiteral("2020-07-02"))))));
    } finally {
        queryRunner.execute("DROP TABLE IF EXISTS test_metadata_aggregation_folding_with_empty_partitions_with_threshold");
    }
}
Also used : Partition(com.facebook.presto.hive.metastore.Partition) Table(com.facebook.presto.hive.metastore.Table) PartitionWithStatistics(com.facebook.presto.hive.metastore.PartitionWithStatistics) StringLiteral(com.facebook.presto.sql.tree.StringLiteral) MetastoreContext(com.facebook.presto.hive.metastore.MetastoreContext) ExtendedHiveMetastore(com.facebook.presto.hive.metastore.ExtendedHiveMetastore) QueryRunner(com.facebook.presto.testing.QueryRunner) DistributedQueryRunner(com.facebook.presto.tests.DistributedQueryRunner) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 10 with ExtendedHiveMetastore

use of com.facebook.presto.hive.metastore.ExtendedHiveMetastore in project presto by prestodb.

the class TestHiveClientFileMetastore method createDummyPartitionedTable.

private void createDummyPartitionedTable(SchemaTableName tableName, List<ColumnMetadata> columns, Map<String, String> dynamicPartitionParameters) throws Exception {
    doCreateEmptyTable(tableName, ORC, columns);
    ExtendedHiveMetastore metastoreClient = getMetastoreClient();
    Table table = metastoreClient.getTable(METASTORE_CONTEXT, tableName.getSchemaName(), tableName.getTableName()).orElseThrow(() -> new TableNotFoundException(tableName));
    List<String> firstPartitionValues = ImmutableList.of("2020-01-01");
    List<String> secondPartitionValues = ImmutableList.of("2020-01-02");
    List<String> thirdPartitionValues = ImmutableList.of("2020-01-03");
    String firstPartitionName = makePartName(ImmutableList.of("ds"), firstPartitionValues);
    String secondPartitionName = makePartName(ImmutableList.of("ds"), secondPartitionValues);
    String thirdPartitionName = makePartName(ImmutableList.of("ds"), thirdPartitionValues);
    List<PartitionWithStatistics> partitions = ImmutableList.of(firstPartitionName, secondPartitionName).stream().map(partitionName -> new PartitionWithStatistics(createDummyPartition(table, partitionName), partitionName, PartitionStatistics.empty())).collect(toImmutableList());
    metastoreClient.addPartitions(METASTORE_CONTEXT, tableName.getSchemaName(), tableName.getTableName(), partitions);
    metastoreClient.updatePartitionStatistics(METASTORE_CONTEXT, tableName.getSchemaName(), tableName.getTableName(), firstPartitionName, currentStatistics -> EMPTY_TABLE_STATISTICS);
    metastoreClient.updatePartitionStatistics(METASTORE_CONTEXT, tableName.getSchemaName(), tableName.getTableName(), secondPartitionName, currentStatistics -> EMPTY_TABLE_STATISTICS);
    List<PartitionWithStatistics> partitionsNotReadable = ImmutableList.of(thirdPartitionName).stream().map(partitionName -> new PartitionWithStatistics(createDummyPartition(table, partitionName, dynamicPartitionParameters), partitionName, PartitionStatistics.empty())).collect(toImmutableList());
    metastoreClient.addPartitions(METASTORE_CONTEXT, tableName.getSchemaName(), tableName.getTableName(), partitionsNotReadable);
    metastoreClient.updatePartitionStatistics(METASTORE_CONTEXT, tableName.getSchemaName(), tableName.getTableName(), thirdPartitionName, currentStatistics -> EMPTY_TABLE_STATISTICS);
}
Also used : SkipException(org.testng.SkipException) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) ORC(com.facebook.presto.hive.HiveStorageFormat.ORC) Table(com.facebook.presto.hive.metastore.Table) PartitionWithStatistics(com.facebook.presto.hive.metastore.PartitionWithStatistics) Assert.assertEquals(org.testng.Assert.assertEquals) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) Test(org.testng.annotations.Test) Partition(com.facebook.presto.hive.metastore.Partition) SchemaTableName(com.facebook.presto.spi.SchemaTableName) WarningCollectorConfig(com.facebook.presto.execution.warnings.WarningCollectorConfig) ImmutableList(com.google.common.collect.ImmutableList) ExtendedHiveMetastore(com.facebook.presto.hive.metastore.ExtendedHiveMetastore) PRESTO_VERSION_NAME(com.facebook.presto.hive.HiveMetadata.PRESTO_VERSION_NAME) Map(java.util.Map) UNGROUPED_SCHEDULING(com.facebook.presto.spi.connector.ConnectorSplitManager.SplitSchedulingStrategy.UNGROUPED_SCHEDULING) OBJECT_NOT_READABLE(com.facebook.presto.hive.HiveSplitManager.OBJECT_NOT_READABLE) METASTORE_CONTEXT(com.facebook.presto.hive.HiveQueryRunner.METASTORE_CONTEXT) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) FileUtils.makePartName(org.apache.hadoop.hive.common.FileUtils.makePartName) ConnectorTableLayout(com.facebook.presto.spi.ConnectorTableLayout) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Assert.fail(org.testng.Assert.fail) Constraint(com.facebook.presto.spi.Constraint) Assert.assertNotNull(org.testng.Assert.assertNotNull) WarningHandlingLevel(com.facebook.presto.execution.warnings.WarningHandlingLevel) File(java.io.File) ConnectorSession(com.facebook.presto.spi.ConnectorSession) List(java.util.List) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) FileHiveMetastore(com.facebook.presto.hive.metastore.file.FileHiveMetastore) ColumnHandle(com.facebook.presto.spi.ColumnHandle) StorageFormat.fromHiveStorageFormat(com.facebook.presto.hive.metastore.StorageFormat.fromHiveStorageFormat) PartitionStatistics(com.facebook.presto.hive.metastore.PartitionStatistics) MetastoreUtil.toPartitionValues(com.facebook.presto.hive.metastore.MetastoreUtil.toPartitionValues) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) DefaultWarningCollector(com.facebook.presto.execution.warnings.DefaultWarningCollector) PRESTO_QUERY_ID_NAME(com.facebook.presto.hive.metastore.MetastoreUtil.PRESTO_QUERY_ID_NAME) SplitSchedulingContext(com.facebook.presto.spi.connector.ConnectorSplitManager.SplitSchedulingContext) NoHdfsAuthentication(com.facebook.presto.hive.authentication.NoHdfsAuthentication) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) Table(com.facebook.presto.hive.metastore.Table) PartitionWithStatistics(com.facebook.presto.hive.metastore.PartitionWithStatistics) ExtendedHiveMetastore(com.facebook.presto.hive.metastore.ExtendedHiveMetastore)

Aggregations

ExtendedHiveMetastore (com.facebook.presto.hive.metastore.ExtendedHiveMetastore)23 Test (org.testng.annotations.Test)12 Table (com.facebook.presto.hive.metastore.Table)10 SchemaTableName (com.facebook.presto.spi.SchemaTableName)10 Partition (com.facebook.presto.hive.metastore.Partition)9 ConnectorSession (com.facebook.presto.spi.ConnectorSession)8 ImmutableMap (com.google.common.collect.ImmutableMap)8 Optional (java.util.Optional)8 PartitionStatistics (com.facebook.presto.hive.metastore.PartitionStatistics)7 PartitionWithStatistics (com.facebook.presto.hive.metastore.PartitionWithStatistics)7 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)7 TestingConnectorSession (com.facebook.presto.testing.TestingConnectorSession)7 ImmutableList (com.google.common.collect.ImmutableList)7 List (java.util.List)7 Assert.assertTrue (org.testng.Assert.assertTrue)7 GroupByHashPageIndexerFactory (com.facebook.presto.GroupByHashPageIndexerFactory)6 REGULAR (com.facebook.presto.hive.HiveColumnHandle.ColumnType.REGULAR)6 HiveTestUtils.getDefaultHiveFileWriterFactories (com.facebook.presto.hive.HiveTestUtils.getDefaultHiveFileWriterFactories)6 HiveTestUtils.getDefaultHiveRecordCursorProvider (com.facebook.presto.hive.HiveTestUtils.getDefaultHiveRecordCursorProvider)6 HIVE_INT (com.facebook.presto.hive.HiveType.HIVE_INT)6