use of org.apache.hadoop.hive.metastore.api.Partition in project hive by apache.
the class TestHBaseStoreIntegration method partitionStatistics.
@Test
public void partitionStatistics() throws Exception {
long now = System.currentTimeMillis();
String dbname = "default";
String tableName = "statspart";
String[] partNames = { "ds=today", "ds=yesterday" };
String[] partVals = { "today", "yesterday" };
String boolcol = "boolcol";
String longcol = "longcol";
String doublecol = "doublecol";
String stringcol = "stringcol";
String binarycol = "bincol";
String decimalcol = "deccol";
long trues = 37;
long falses = 12;
long booleanNulls = 2;
long strMaxLen = 1234;
double strAvgLen = 32.3;
long strNulls = 987;
long strDVs = 906;
List<FieldSchema> cols = new ArrayList<FieldSchema>();
cols.add(new FieldSchema(boolcol, "boolean", "nocomment"));
cols.add(new FieldSchema(longcol, "long", "nocomment"));
cols.add(new FieldSchema(doublecol, "double", "nocomment"));
cols.add(new FieldSchema(stringcol, "varchar(32)", "nocomment"));
cols.add(new FieldSchema(binarycol, "binary", "nocomment"));
cols.add(new FieldSchema(decimalcol, "decimal(5, 3)", "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", ""));
Table table = new Table(tableName, dbname, "me", (int) now / 1000, (int) now / 1000, 0, sd, partCols, emptyParameters, null, null, null);
store.createTable(table);
for (String partVal : partVals) {
Partition part = new Partition(Arrays.asList(partVal), dbname, tableName, (int) now / 1000, (int) now / 1000, sd, emptyParameters);
store.addPartition(part);
}
for (int i = 0; i < partNames.length; i++) {
ColumnStatistics stats = new ColumnStatistics();
ColumnStatisticsDesc desc = new ColumnStatisticsDesc();
desc.setLastAnalyzed(now);
desc.setDbName(dbname);
desc.setTableName(tableName);
desc.setIsTblLevel(false);
desc.setPartName(partNames[i]);
stats.setStatsDesc(desc);
ColumnStatisticsObj obj = new ColumnStatisticsObj();
obj.setColName(boolcol);
obj.setColType("boolean");
ColumnStatisticsData data = new ColumnStatisticsData();
BooleanColumnStatsData boolData = new BooleanColumnStatsData();
boolData.setNumTrues(trues);
boolData.setNumFalses(falses);
boolData.setNumNulls(booleanNulls);
data.setBooleanStats(boolData);
obj.setStatsData(data);
stats.addToStatsObj(obj);
store.updatePartitionColumnStatistics(stats, Arrays.asList(partVals[i]));
}
List<ColumnStatistics> statsList = store.getPartitionColumnStatistics(dbname, tableName, Arrays.asList(partNames), Arrays.asList(boolcol));
Assert.assertEquals(2, statsList.size());
for (int i = 0; i < partNames.length; i++) {
Assert.assertEquals(1, statsList.get(i).getStatsObjSize());
}
for (int i = 0; i < partNames.length; i++) {
ColumnStatistics stats = new ColumnStatistics();
ColumnStatisticsDesc desc = new ColumnStatisticsDesc();
desc.setLastAnalyzed(now);
desc.setDbName(dbname);
desc.setTableName(tableName);
desc.setIsTblLevel(false);
desc.setPartName(partNames[i]);
stats.setStatsDesc(desc);
ColumnStatisticsObj obj = new ColumnStatisticsObj();
obj.setColName(stringcol);
obj.setColType("string");
ColumnStatisticsData data = new ColumnStatisticsData();
StringColumnStatsData strData = new StringColumnStatsData();
strData.setMaxColLen(strMaxLen);
strData.setAvgColLen(strAvgLen);
strData.setNumNulls(strNulls);
strData.setNumDVs(strDVs);
data.setStringStats(strData);
obj.setStatsData(data);
stats.addToStatsObj(obj);
store.updatePartitionColumnStatistics(stats, Arrays.asList(partVals[i]));
}
// Make sure when we ask for one we only get one
statsList = store.getPartitionColumnStatistics(dbname, tableName, Arrays.asList(partNames), Arrays.asList(boolcol));
Assert.assertEquals(2, statsList.size());
for (int i = 0; i < partNames.length; i++) {
Assert.assertEquals(1, statsList.get(i).getStatsObjSize());
}
statsList = store.getPartitionColumnStatistics(dbname, tableName, Arrays.asList(partNames), Arrays.asList(boolcol, stringcol));
Assert.assertEquals(2, statsList.size());
for (int i = 0; i < partNames.length; i++) {
Assert.assertEquals(2, statsList.get(i).getStatsObjSize());
// Just check one piece of the data, I don't need to check it all again
Assert.assertEquals(booleanNulls, statsList.get(i).getStatsObj().get(0).getStatsData().getBooleanStats().getNumNulls());
Assert.assertEquals(strDVs, statsList.get(i).getStatsObj().get(1).getStatsData().getStringStats().getNumDVs());
}
}
use of org.apache.hadoop.hive.metastore.api.Partition 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());
}
use of org.apache.hadoop.hive.metastore.api.Partition 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);
}
use of org.apache.hadoop.hive.metastore.api.Partition 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();
}
}
use of org.apache.hadoop.hive.metastore.api.Partition in project hive by apache.
the class TestReplicationScenarios method testBasicWithCM.
@Test
public void testBasicWithCM() throws Exception {
String testName = "basic_with_cm";
LOG.info("Testing " + testName);
String dbName = testName + "_" + tid;
run("CREATE DATABASE " + dbName);
run("CREATE TABLE " + dbName + ".unptned(a string) STORED AS TEXTFILE");
run("CREATE TABLE " + dbName + ".ptned(a string) partitioned by (b int) STORED AS TEXTFILE");
run("CREATE TABLE " + dbName + ".unptned_empty(a string) STORED AS TEXTFILE");
run("CREATE TABLE " + dbName + ".ptned_empty(a string) partitioned by (b int) STORED AS TEXTFILE");
String[] unptn_data = new String[] { "eleven", "twelve" };
String[] ptn_data_1 = new String[] { "thirteen", "fourteen", "fifteen" };
String[] ptn_data_2 = new String[] { "fifteen", "sixteen", "seventeen" };
String[] ptn_data_2_later = new String[] { "eighteen", "nineteen", "twenty" };
String[] empty = new String[] {};
String unptn_locn = new Path(TEST_PATH, testName + "_unptn").toUri().getPath();
String ptn_locn_1 = new Path(TEST_PATH, testName + "_ptn1").toUri().getPath();
String ptn_locn_2 = new Path(TEST_PATH, testName + "_ptn2").toUri().getPath();
String ptn_locn_2_later = new Path(TEST_PATH, testName + "_ptn2_later").toUri().getPath();
createTestDataFile(unptn_locn, unptn_data);
createTestDataFile(ptn_locn_1, ptn_data_1);
createTestDataFile(ptn_locn_2, ptn_data_2);
createTestDataFile(ptn_locn_2_later, ptn_data_2_later);
run("LOAD DATA LOCAL INPATH '" + unptn_locn + "' OVERWRITE INTO TABLE " + dbName + ".unptned");
run("SELECT * from " + dbName + ".unptned");
verifyResults(unptn_data);
run("LOAD DATA LOCAL INPATH '" + ptn_locn_1 + "' OVERWRITE INTO TABLE " + dbName + ".ptned PARTITION(b=1)");
run("SELECT a from " + dbName + ".ptned WHERE b=1");
verifyResults(ptn_data_1);
run("LOAD DATA LOCAL INPATH '" + ptn_locn_2 + "' OVERWRITE INTO TABLE " + dbName + ".ptned PARTITION(b=2)");
run("SELECT a from " + dbName + ".ptned WHERE b=2");
verifyResults(ptn_data_2);
run("SELECT a from " + dbName + ".ptned_empty");
verifyResults(empty);
run("SELECT * from " + dbName + ".unptned_empty");
verifyResults(empty);
advanceDumpDir();
run("REPL DUMP " + dbName);
String replDumpLocn = getResult(0, 0);
String replDumpId = getResult(0, 1, true);
// Table dropped after "repl dump"
run("DROP TABLE " + dbName + ".unptned");
// Partition droppped after "repl dump"
run("ALTER TABLE " + dbName + ".ptned " + "DROP PARTITION(b=1)");
// File changed after "repl dump"
Partition p = metaStoreClient.getPartition(dbName, "ptned", "b=2");
Path loc = new Path(p.getSd().getLocation());
FileSystem fs = loc.getFileSystem(hconf);
Path file = fs.listStatus(loc)[0].getPath();
fs.delete(file, false);
fs.copyFromLocalFile(new Path(ptn_locn_2_later), file);
run("EXPLAIN REPL LOAD " + dbName + "_dupe FROM '" + replDumpLocn + "'");
printOutput();
run("REPL LOAD " + dbName + "_dupe FROM '" + replDumpLocn + "'");
run("REPL STATUS " + dbName + "_dupe");
verifyResults(new String[] { replDumpId });
run("SELECT * from " + dbName + "_dupe.unptned");
verifyResults(unptn_data);
run("SELECT a from " + dbName + "_dupe.ptned WHERE b=1");
verifyResults(ptn_data_1);
// Since partition(b=2) changed manually, Hive cannot find
// it in original location and cmroot, thus empty
run("SELECT a from " + dbName + "_dupe.ptned WHERE b=2");
verifyResults(empty);
run("SELECT a from " + dbName + ".ptned_empty");
verifyResults(empty);
run("SELECT * from " + dbName + ".unptned_empty");
verifyResults(empty);
}
Aggregations