Search in sources :

Example 6 with StorageDescriptor

use of org.apache.hadoop.hive.metastore.api.StorageDescriptor in project hive by apache.

the class TestHBaseStoreIntegration method listPartitions.

@Test
public void listPartitions() throws Exception {
    String dbName = "default";
    String tableName = "listParts";
    int startTime = (int) (System.currentTimeMillis() / 1000);
    List<FieldSchema> cols = new ArrayList<FieldSchema>();
    cols.add(new FieldSchema("col1", "int", "nocomment"));
    SerDeInfo serde = new SerDeInfo("serde", "seriallib", null);
    StorageDescriptor sd = new StorageDescriptor(cols, "file:/tmp", "input", "output", false, 0, serde, null, null, emptyParameters);
    List<FieldSchema> partCols = new ArrayList<FieldSchema>();
    partCols.add(new FieldSchema("pc", "string", ""));
    partCols.add(new FieldSchema("region", "string", ""));
    Table table = new Table(tableName, dbName, "me", startTime, startTime, 0, sd, partCols, emptyParameters, null, null, null);
    store.createTable(table);
    String[][] partVals = new String[][] { { "today", "north america" }, { "tomorrow", "europe" } };
    for (String[] pv : partVals) {
        List<String> vals = new ArrayList<String>();
        for (String v : pv) vals.add(v);
        StorageDescriptor psd = new StorageDescriptor(sd);
        psd.setLocation("file:/tmp/pc=" + pv[0] + "/region=" + pv[1]);
        Partition part = new Partition(vals, dbName, tableName, startTime, startTime, psd, emptyParameters);
        store.addPartition(part);
    }
    List<String> names = store.listPartitionNames(dbName, tableName, (short) -1);
    Assert.assertEquals(2, names.size());
    String[] resultNames = names.toArray(new String[names.size()]);
    Arrays.sort(resultNames);
    Assert.assertArrayEquals(resultNames, new String[] { "pc=today/region=north america", "pc=tomorrow/region=europe" });
    List<Partition> parts = store.getPartitionsByNames(dbName, tableName, names);
    Assert.assertArrayEquals(partVals[0], parts.get(0).getValues().toArray(new String[2]));
    Assert.assertArrayEquals(partVals[1], parts.get(1).getValues().toArray(new String[2]));
    store.dropPartitions(dbName, tableName, names);
    List<Partition> afterDropParts = store.getPartitions(dbName, tableName, -1);
    Assert.assertEquals(0, afterDropParts.size());
}
Also used : Partition(org.apache.hadoop.hive.metastore.api.Partition) Table(org.apache.hadoop.hive.metastore.api.Table) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) SerDeInfo(org.apache.hadoop.hive.metastore.api.SerDeInfo) ArrayList(java.util.ArrayList) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) Test(org.junit.Test)

Example 7 with StorageDescriptor

use of org.apache.hadoop.hive.metastore.api.StorageDescriptor in project hive by apache.

the class TestHBaseStoreIntegration method getAllTables.

@Test
public void getAllTables() throws Exception {
    // named to match getAllDbs so we get the
    String[] dbNames = new String[] { "db0", "db1" };
    // right number of databases in that test.
    String[] tableNames = new String[] { "curly", "larry", "moe" };
    for (int i = 0; i < dbNames.length; i++) {
        store.createDatabase(new Database(dbNames[i], "no description", "file:///tmp", emptyParameters));
    }
    for (int i = 0; i < dbNames.length; i++) {
        for (int j = 0; j < tableNames.length; j++) {
            int startTime = (int) (System.currentTimeMillis() / 1000);
            List<FieldSchema> cols = new ArrayList<FieldSchema>();
            cols.add(new FieldSchema("col1", "int", "nocomment"));
            SerDeInfo serde = new SerDeInfo("serde", "seriallib", null);
            StorageDescriptor sd = new StorageDescriptor(cols, "file:/tmp", "input", "output", false, 0, serde, null, null, emptyParameters);
            Table table = new Table(tableNames[j], dbNames[i], "me", startTime, startTime, 0, sd, null, emptyParameters, null, null, null);
            store.createTable(table);
        }
    }
    List<String> fetchedNames = store.getAllTables(dbNames[0]);
    Assert.assertEquals(3, fetchedNames.size());
    String[] sortedFetchedNames = fetchedNames.toArray(new String[fetchedNames.size()]);
    Arrays.sort(sortedFetchedNames);
    Assert.assertArrayEquals(tableNames, sortedFetchedNames);
    List<String> regexNames = store.getTables(dbNames[0], "*y");
    Assert.assertEquals(2, regexNames.size());
    String[] sortedRegexNames = regexNames.toArray(new String[regexNames.size()]);
    Arrays.sort(sortedRegexNames);
    Assert.assertArrayEquals(Arrays.copyOfRange(tableNames, 0, 2), sortedRegexNames);
    List<Table> fetchedTables = store.getTableObjectsByName(dbNames[1], Arrays.asList(Arrays.copyOfRange(tableNames, 1, 3)));
    Assert.assertEquals(2, fetchedTables.size());
    sortedFetchedNames = new String[fetchedTables.size()];
    for (int i = 0; i < fetchedTables.size(); i++) {
        sortedFetchedNames[i] = fetchedTables.get(i).getTableName();
    }
    Arrays.sort(sortedFetchedNames);
    Assert.assertArrayEquals(Arrays.copyOfRange(tableNames, 1, 3), sortedFetchedNames);
}
Also used : Table(org.apache.hadoop.hive.metastore.api.Table) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) SerDeInfo(org.apache.hadoop.hive.metastore.api.SerDeInfo) Database(org.apache.hadoop.hive.metastore.api.Database) ArrayList(java.util.ArrayList) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) Test(org.junit.Test)

Example 8 with StorageDescriptor

use of org.apache.hadoop.hive.metastore.api.StorageDescriptor in project hive by apache.

the class TestHBaseStoreIntegration method dropTable.

@Test
public void dropTable() throws Exception {
    String tableName = "dtable";
    int startTime = (int) (System.currentTimeMillis() / 1000);
    List<FieldSchema> cols = new ArrayList<FieldSchema>();
    cols.add(new FieldSchema("col1", "int", "nocomment"));
    SerDeInfo serde = new SerDeInfo("serde", "seriallib", null);
    StorageDescriptor sd = new StorageDescriptor(cols, "file:/tmp", "input", "output", false, 0, serde, null, null, emptyParameters);
    Table table = new Table(tableName, "default", "me", startTime, startTime, 0, sd, null, emptyParameters, null, null, null);
    store.createTable(table);
    Table t = store.getTable("default", tableName);
    Assert.assertNotNull(t);
    store.dropTable("default", tableName);
    Assert.assertNull(store.getTable("default", tableName));
}
Also used : Table(org.apache.hadoop.hive.metastore.api.Table) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) SerDeInfo(org.apache.hadoop.hive.metastore.api.SerDeInfo) ArrayList(java.util.ArrayList) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) Test(org.junit.Test)

Example 9 with StorageDescriptor

use of org.apache.hadoop.hive.metastore.api.StorageDescriptor in project hive by apache.

the class TestHBaseStoreIntegration method listPartitionsWithPs.

@Test
public void listPartitionsWithPs() throws Exception {
    String dbName = "default";
    String tableName = "listPartitionsWithPs";
    int startTime = (int) (System.currentTimeMillis() / 1000);
    List<FieldSchema> cols = new ArrayList<FieldSchema>();
    cols.add(new FieldSchema("col1", "int", "nocomment"));
    SerDeInfo serde = new SerDeInfo("serde", "seriallib", null);
    StorageDescriptor sd = new StorageDescriptor(cols, "file:/tmp", "input", "output", false, 0, serde, null, null, emptyParameters);
    List<FieldSchema> partCols = new ArrayList<FieldSchema>();
    partCols.add(new FieldSchema("ds", "string", ""));
    partCols.add(new FieldSchema("region", "string", ""));
    Table table = new Table(tableName, dbName, "me", startTime, startTime, 0, sd, partCols, emptyParameters, null, null, null);
    store.createTable(table);
    String[][] partVals = new String[][] { { "today", "north america" }, { "today", "europe" }, { "tomorrow", "north america" }, { "tomorrow", "europe" } };
    for (String[] pv : partVals) {
        List<String> vals = new ArrayList<String>();
        for (String v : pv) vals.add(v);
        StorageDescriptor psd = new StorageDescriptor(sd);
        psd.setLocation("file:/tmp/ds=" + pv[0] + "/region=" + pv[1]);
        Partition part = new Partition(vals, dbName, tableName, startTime, startTime, psd, emptyParameters);
        store.addPartition(part);
    }
    // We only test listPartitionNamesPs since it calls listPartitionsPsWithAuth anyway.
    // Test the case where we completely specify the partition
    List<String> partitionNames = store.listPartitionNamesPs(dbName, tableName, Arrays.asList(partVals[0]), (short) -1);
    Assert.assertEquals(1, partitionNames.size());
    Assert.assertEquals("ds=today/region=north america", partitionNames.get(0));
    // Leave off the last value of the partition
    partitionNames = store.listPartitionNamesPs(dbName, tableName, Arrays.asList(partVals[0][0]), (short) -1);
    Assert.assertEquals(2, partitionNames.size());
    String[] names = partitionNames.toArray(new String[partitionNames.size()]);
    Arrays.sort(names);
    Assert.assertArrayEquals(new String[] { "ds=today/region=europe", "ds=today/region=north america" }, names);
    // Put a star in the last value of the partition
    partitionNames = store.listPartitionNamesPs(dbName, tableName, Arrays.asList("today", "*"), (short) -1);
    Assert.assertEquals(2, partitionNames.size());
    names = partitionNames.toArray(new String[partitionNames.size()]);
    Arrays.sort(names);
    Assert.assertArrayEquals(new String[] { "ds=today/region=europe", "ds=today/region=north america" }, names);
    // Put a star in the first value of the partition
    partitionNames = store.listPartitionNamesPs(dbName, tableName, Arrays.asList("*", "europe"), (short) -1);
    Assert.assertEquals(2, partitionNames.size());
    names = partitionNames.toArray(new String[partitionNames.size()]);
    Arrays.sort(names);
    Assert.assertArrayEquals(new String[] { "ds=today/region=europe", "ds=tomorrow/region=europe" }, names);
}
Also used : Partition(org.apache.hadoop.hive.metastore.api.Partition) Table(org.apache.hadoop.hive.metastore.api.Table) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) SerDeInfo(org.apache.hadoop.hive.metastore.api.SerDeInfo) ArrayList(java.util.ArrayList) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) Test(org.junit.Test)

Example 10 with StorageDescriptor

use of org.apache.hadoop.hive.metastore.api.StorageDescriptor in project hive by apache.

the class TestHBaseAggrStatsCacheIntegration method alterInvalidation.

@Test
public void alterInvalidation() throws Exception {
    try {
        String dbName = "default";
        String tableName = "ai";
        List<String> partVals1 = Arrays.asList("today");
        List<String> partVals2 = Arrays.asList("yesterday");
        List<String> partVals3 = Arrays.asList("tomorrow");
        long now = System.currentTimeMillis();
        List<FieldSchema> cols = new ArrayList<>();
        cols.add(new FieldSchema("col1", "boolean", "nocomment"));
        SerDeInfo serde = new SerDeInfo("serde", "seriallib", null);
        StorageDescriptor sd = new StorageDescriptor(cols, "file:/tmp", "input", "output", false, 0, serde, null, null, Collections.<String, String>emptyMap());
        List<FieldSchema> partCols = new ArrayList<>();
        partCols.add(new FieldSchema("ds", "string", ""));
        Table table = new Table(tableName, dbName, "me", (int) now, (int) now, 0, sd, partCols, Collections.<String, String>emptyMap(), null, null, null);
        store.createTable(table);
        Partition[] partitions = new Partition[3];
        int partnum = 0;
        for (List<String> partVals : Arrays.asList(partVals1, partVals2, partVals3)) {
            StorageDescriptor psd = new StorageDescriptor(sd);
            psd.setLocation("file:/tmp/default/invalidation/ds=" + partVals.get(0));
            Partition part = new Partition(partVals, dbName, tableName, (int) now, (int) now, psd, Collections.<String, String>emptyMap());
            partitions[partnum++] = part;
            store.addPartition(part);
            ColumnStatistics cs = new ColumnStatistics();
            ColumnStatisticsDesc desc = new ColumnStatisticsDesc(false, dbName, tableName);
            desc.setLastAnalyzed(now);
            desc.setPartName("ds=" + partVals.get(0));
            cs.setStatsDesc(desc);
            ColumnStatisticsObj obj = new ColumnStatisticsObj();
            obj.setColName("col1");
            obj.setColType("boolean");
            ColumnStatisticsData data = new ColumnStatisticsData();
            BooleanColumnStatsData bcsd = new BooleanColumnStatsData();
            bcsd.setNumFalses(10);
            bcsd.setNumTrues(20);
            bcsd.setNumNulls(30);
            data.setBooleanStats(bcsd);
            obj.setStatsData(data);
            cs.addToStatsObj(obj);
            store.updatePartitionColumnStatistics(cs, partVals);
        }
        AggrStats aggrStats = store.get_aggr_stats_for(dbName, tableName, Arrays.asList("ds=today", "ds=tomorrow"), Arrays.asList("col1"));
        aggrStats = store.get_aggr_stats_for(dbName, tableName, Arrays.asList("ds=today", "ds=yesterday"), Arrays.asList("col1"));
        // Check that we had to build it from the stats
        Assert.assertEquals(0, store.backdoor().getStatsCache().hbaseHits.getCnt());
        Assert.assertEquals(2, store.backdoor().getStatsCache().totalGets.getCnt());
        Assert.assertEquals(2, store.backdoor().getStatsCache().misses.getCnt());
        // wake the invalidator and check again to make sure it isn't too aggressive about
        // removing our stuff.
        store.backdoor().getStatsCache().wakeInvalidator();
        Partition newPart = new Partition(partitions[2]);
        newPart.setLastAccessTime((int) System.currentTimeMillis());
        store.alterPartition(dbName, tableName, partVals3, newPart);
        store.backdoor().getStatsCache().setRunInvalidatorEvery(100);
        store.backdoor().getStatsCache().wakeInvalidator();
        aggrStats = store.get_aggr_stats_for(dbName, tableName, Arrays.asList("ds=tomorrow", "ds=today"), Arrays.asList("col1"));
        // Check that we missed, which means this aggregate was dropped from the cache.
        Assert.assertEquals(0, store.backdoor().getStatsCache().hbaseHits.getCnt());
        Assert.assertEquals(3, store.backdoor().getStatsCache().totalGets.getCnt());
        Assert.assertEquals(3, store.backdoor().getStatsCache().misses.getCnt());
        // Check that our other aggregate is still in the cache.
        aggrStats = store.get_aggr_stats_for(dbName, tableName, Arrays.asList("ds=yesterday", "ds=today"), Arrays.asList("col1"));
        Assert.assertEquals(0, store.backdoor().getStatsCache().hbaseHits.getCnt());
        Assert.assertEquals(4, store.backdoor().getStatsCache().totalGets.getCnt());
        Assert.assertEquals(3, store.backdoor().getStatsCache().misses.getCnt());
    } finally {
        store.backdoor().getStatsCache().setRunInvalidatorEvery(5000);
        store.backdoor().getStatsCache().setMaxTimeInCache(500000);
        store.backdoor().getStatsCache().wakeInvalidator();
    }
}
Also used : ColumnStatistics(org.apache.hadoop.hive.metastore.api.ColumnStatistics) BooleanColumnStatsData(org.apache.hadoop.hive.metastore.api.BooleanColumnStatsData) Partition(org.apache.hadoop.hive.metastore.api.Partition) Table(org.apache.hadoop.hive.metastore.api.Table) AggrStats(org.apache.hadoop.hive.metastore.api.AggrStats) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) SerDeInfo(org.apache.hadoop.hive.metastore.api.SerDeInfo) ArrayList(java.util.ArrayList) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) ColumnStatisticsObj(org.apache.hadoop.hive.metastore.api.ColumnStatisticsObj) ColumnStatisticsDesc(org.apache.hadoop.hive.metastore.api.ColumnStatisticsDesc) ColumnStatisticsData(org.apache.hadoop.hive.metastore.api.ColumnStatisticsData) Test(org.junit.Test)

Aggregations

StorageDescriptor (org.apache.hadoop.hive.metastore.api.StorageDescriptor)191 SerDeInfo (org.apache.hadoop.hive.metastore.api.SerDeInfo)139 Table (org.apache.hadoop.hive.metastore.api.Table)139 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)138 ArrayList (java.util.ArrayList)126 Test (org.junit.Test)103 Partition (org.apache.hadoop.hive.metastore.api.Partition)78 HashMap (java.util.HashMap)49 Order (org.apache.hadoop.hive.metastore.api.Order)32 Database (org.apache.hadoop.hive.metastore.api.Database)31 List (java.util.List)28 ColumnStatistics (org.apache.hadoop.hive.metastore.api.ColumnStatistics)28 ColumnStatisticsData (org.apache.hadoop.hive.metastore.api.ColumnStatisticsData)28 ColumnStatisticsDesc (org.apache.hadoop.hive.metastore.api.ColumnStatisticsDesc)28 ColumnStatisticsObj (org.apache.hadoop.hive.metastore.api.ColumnStatisticsObj)28 AggrStats (org.apache.hadoop.hive.metastore.api.AggrStats)26 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)26 LazySimpleSerDe (org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe)21 HiveInputFormat (org.apache.hadoop.hive.ql.io.HiveInputFormat)18 HiveOutputFormat (org.apache.hadoop.hive.ql.io.HiveOutputFormat)18