org.apache.hadoop.hive.metastore.api.LongColumnStatsData Java Examples

The following examples show how to use org.apache.hadoop.hive.metastore.api.LongColumnStatsData. 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: TestThriftMetastoreUtil.java    From presto with Apache License 2.0 6 votes vote down vote up
@Test
public void testLongStatsToColumnStatistics()
{
    LongColumnStatsData longColumnStatsData = new LongColumnStatsData();
    longColumnStatsData.setLowValue(0);
    longColumnStatsData.setHighValue(100);
    longColumnStatsData.setNumNulls(1);
    longColumnStatsData.setNumDVs(20);
    ColumnStatisticsObj columnStatisticsObj = new ColumnStatisticsObj("my_col", BIGINT_TYPE_NAME, longStats(longColumnStatsData));
    HiveColumnStatistics actual = fromMetastoreApiColumnStatistics(columnStatisticsObj, OptionalLong.of(1000));

    assertEquals(actual.getIntegerStatistics(), Optional.of(new IntegerStatistics(OptionalLong.of(0), OptionalLong.of(100))));
    assertEquals(actual.getDoubleStatistics(), Optional.empty());
    assertEquals(actual.getDecimalStatistics(), Optional.empty());
    assertEquals(actual.getDateStatistics(), Optional.empty());
    assertEquals(actual.getBooleanStatistics(), Optional.empty());
    assertEquals(actual.getMaxValueSizeInBytes(), OptionalLong.empty());
    assertEquals(actual.getTotalSizeInBytes(), OptionalLong.empty());
    assertEquals(actual.getNullsCount(), OptionalLong.of(1));
    assertEquals(actual.getDistinctValuesCount(), OptionalLong.of(19));
}
 
Example #2
Source File: TestThriftMetastoreUtil.java    From presto with Apache License 2.0 6 votes vote down vote up
@Test
public void testEmptyLongStatsToColumnStatistics()
{
    LongColumnStatsData emptyLongColumnStatsData = new LongColumnStatsData();
    ColumnStatisticsObj columnStatisticsObj = new ColumnStatisticsObj("my_col", BIGINT_TYPE_NAME, longStats(emptyLongColumnStatsData));
    HiveColumnStatistics actual = fromMetastoreApiColumnStatistics(columnStatisticsObj, OptionalLong.empty());

    assertEquals(actual.getIntegerStatistics(), Optional.of(new IntegerStatistics(OptionalLong.empty(), OptionalLong.empty())));
    assertEquals(actual.getDoubleStatistics(), Optional.empty());
    assertEquals(actual.getDecimalStatistics(), Optional.empty());
    assertEquals(actual.getDateStatistics(), Optional.empty());
    assertEquals(actual.getBooleanStatistics(), Optional.empty());
    assertEquals(actual.getMaxValueSizeInBytes(), OptionalLong.empty());
    assertEquals(actual.getTotalSizeInBytes(), OptionalLong.empty());
    assertEquals(actual.getNullsCount(), OptionalLong.empty());
    assertEquals(actual.getDistinctValuesCount(), OptionalLong.empty());
}
 
Example #3
Source File: TestObjects.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 5 votes vote down vote up
public static org.apache.hadoop.hive.metastore.api.ColumnStatisticsData getHiveLongColumnStatsData() {
  LongColumnStatsData statsData = new LongColumnStatsData();
  statsData.setHighValue(9999L);
  statsData.setLowValue(-1111L);
  statsData.setNumDVs(123L);
  statsData.setNumNulls(456L);
  org.apache.hadoop.hive.metastore.api.ColumnStatisticsData  statsWrapper =
          new org.apache.hadoop.hive.metastore.api.ColumnStatisticsData();
  statsWrapper.setLongStats(statsData);
  return statsWrapper;
}
 
Example #4
Source File: ThriftMetastoreUtil.java    From presto with Apache License 2.0 5 votes vote down vote up
private static ColumnStatisticsObj createLongStatistics(String columnName, HiveType columnType, HiveColumnStatistics statistics)
{
    LongColumnStatsData data = new LongColumnStatsData();
    statistics.getIntegerStatistics().ifPresent(integerStatistics -> {
        integerStatistics.getMin().ifPresent(data::setLowValue);
        integerStatistics.getMax().ifPresent(data::setHighValue);
    });
    statistics.getNullsCount().ifPresent(data::setNumNulls);
    toMetastoreDistinctValuesCount(statistics.getDistinctValuesCount(), statistics.getNullsCount()).ifPresent(data::setNumDVs);
    return new ColumnStatisticsObj(columnName, columnType.toString(), longStats(data));
}
 
Example #5
Source File: MockThriftMetastoreClient.java    From presto with Apache License 2.0 5 votes vote down vote up
private static ColumnStatisticsObj createTestStats()
{
    ColumnStatisticsObj stats = new ColumnStatisticsObj();
    ColumnStatisticsData data = new ColumnStatisticsData();
    data.setLongStats(new LongColumnStatsData());
    stats.setStatsData(data);
    stats.setColName(TEST_COLUMN);
    return stats;
}
 
Example #6
Source File: ReplicaTest.java    From circus-train with Apache License 2.0 5 votes vote down vote up
@Before
public void prepare() throws Exception {
  when(metaStoreClientSupplier.get()).thenReturn(mockMetaStoreClient);
  when(replicaCatalog.getName()).thenReturn(NAME);

  hiveConf = new HiveConf();
  hiveConf.setVar(ConfVars.METASTOREURIS, REPLICA_META_STORE_URIS);
  replica = newReplica(tableReplication);
  tableLocation = temporaryFolder.newFolder("table_location").toURI().toString();

  sourceTable = newTable();
  existingPartition = newPartition("one", "two");

  ColumnStatisticsObj columnStatisticsObj1 = new ColumnStatisticsObj(COLUMN_A, "string",
      new ColumnStatisticsData(_Fields.LONG_STATS, new LongColumnStatsData(0, 1)));
  ColumnStatisticsObj columnStatisticsObj2 = new ColumnStatisticsObj(COLUMN_B, "string",
      new ColumnStatisticsData(_Fields.LONG_STATS, new LongColumnStatsData(1, 2)));
  columnStatisticsObjs = Arrays.asList(columnStatisticsObj1, columnStatisticsObj2);
  ColumnStatisticsDesc statsDesc = new ColumnStatisticsDesc(true, DB_NAME, TABLE_NAME);
  columnStatistics = new ColumnStatistics(statsDesc, columnStatisticsObjs);

  tableAndStatistics = new TableAndStatistics(sourceTable, columnStatistics);

  existingReplicaTable = new Table(sourceTable);

  when(mockReplicaLocationManager.getTableLocation()).thenReturn(new Path(tableLocation));
  when(mockReplicaLocationManager.getPartitionBaseLocation()).thenReturn(new Path(tableLocation));

  when(mockMetaStoreClient.getTable(DB_NAME, TABLE_NAME)).thenReturn(existingReplicaTable);
}
 
Example #7
Source File: ReplicaTest.java    From circus-train with Apache License 2.0 5 votes vote down vote up
private ColumnStatistics newPartitionStatistics(String... values) {
  ColumnStatisticsObj columnStatisticsObj1 = new ColumnStatisticsObj(COLUMN_A, "string",
      new ColumnStatisticsData(_Fields.LONG_STATS, new LongColumnStatsData(0, 1)));
  ColumnStatisticsObj columnStatisticsObj2 = new ColumnStatisticsObj(COLUMN_B, "string",
      new ColumnStatisticsData(_Fields.LONG_STATS, new LongColumnStatsData(1, 2)));
  List<ColumnStatisticsObj> columnStatisticsObjs = Arrays.asList(columnStatisticsObj1, columnStatisticsObj2);
  ColumnStatisticsDesc statsDesc = new ColumnStatisticsDesc(false, DB_NAME, TABLE_NAME);
  statsDesc.setPartName(partitionName(values));
  return new ColumnStatistics(statsDesc, columnStatisticsObjs);
}
 
Example #8
Source File: TestUtils.java    From circus-train with Apache License 2.0 5 votes vote down vote up
public static Table createUnpartitionedTable(
    HiveMetaStoreClient metaStoreClient,
    String database,
    String table,
    URI location)
  throws TException {
  Table hiveTable = new Table();
  hiveTable.setDbName(database);
  hiveTable.setTableName(table);
  hiveTable.setTableType(TableType.EXTERNAL_TABLE.name());
  hiveTable.putToParameters("EXTERNAL", "TRUE");

  StorageDescriptor sd = new StorageDescriptor();
  sd.setCols(DATA_COLUMNS);
  sd.setLocation(location.toString());
  sd.setParameters(new HashMap<String, String>());
  sd.setInputFormat(TextInputFormat.class.getName());
  sd.setOutputFormat(TextOutputFormat.class.getName());
  sd.setSerdeInfo(new SerDeInfo());
  sd.getSerdeInfo().setSerializationLib("org.apache.hadoop.hive.serde2.OpenCSVSerde");

  hiveTable.setSd(sd);

  metaStoreClient.createTable(hiveTable);

  ColumnStatisticsDesc statsDesc = new ColumnStatisticsDesc(true, database, table);
  ColumnStatisticsData statsData = new ColumnStatisticsData(_Fields.LONG_STATS, new LongColumnStatsData(1L, 2L));
  ColumnStatisticsObj cso1 = new ColumnStatisticsObj("id", "bigint", statsData);
  List<ColumnStatisticsObj> statsObj = Collections.singletonList(cso1);
  metaStoreClient.updateTableColumnStatistics(new ColumnStatistics(statsDesc, statsObj));

  return hiveTable;
}
 
Example #9
Source File: ColumnStatisticsTransformationTest.java    From circus-train with Apache License 2.0 5 votes vote down vote up
@Before
public void init() {
  stats = new ColumnStatistics(new ColumnStatisticsDesc(true, "database", "table"),
      ImmutableList.of(
          new ColumnStatisticsObj("a", "int",
              new ColumnStatisticsData(_Fields.LONG_STATS, new LongColumnStatsData(1L, 2L))),
          new ColumnStatisticsObj("b", "string",
              new ColumnStatisticsData(_Fields.STRING_STATS, new StringColumnStatsData(10L, 3L, 0L, 1L)))));
}
 
Example #10
Source File: HiveStatsUtil.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Create Flink ColumnStats from Hive ColumnStatisticsData.
 */
private static CatalogColumnStatisticsDataBase createTableColumnStats(DataType colType, ColumnStatisticsData stats) {
	if (stats.isSetBinaryStats()) {
		BinaryColumnStatsData binaryStats = stats.getBinaryStats();
		return new CatalogColumnStatisticsDataBinary(
				binaryStats.getMaxColLen(),
				binaryStats.getAvgColLen(),
				binaryStats.getNumNulls());
	} else if (stats.isSetBooleanStats()) {
		BooleanColumnStatsData booleanStats = stats.getBooleanStats();
		return new CatalogColumnStatisticsDataBoolean(
				booleanStats.getNumTrues(),
				booleanStats.getNumFalses(),
				booleanStats.getNumNulls());
	} else if (stats.isSetDateStats()) {
		DateColumnStatsData dateStats = stats.getDateStats();
		return new CatalogColumnStatisticsDataDate(
				new org.apache.flink.table.catalog.stats.Date(dateStats.getLowValue().getDaysSinceEpoch()),
				new org.apache.flink.table.catalog.stats.Date(dateStats.getHighValue().getDaysSinceEpoch()),
				dateStats.getNumDVs(),
				dateStats.getNumNulls());
	} else if (stats.isSetDoubleStats()) {
			DoubleColumnStatsData doubleStats = stats.getDoubleStats();
			return new CatalogColumnStatisticsDataDouble(
					doubleStats.getLowValue(),
					doubleStats.getHighValue(),
					doubleStats.getNumDVs(),
					doubleStats.getNumNulls());
	} else if (stats.isSetLongStats()) {
			LongColumnStatsData longColStats = stats.getLongStats();
			return new CatalogColumnStatisticsDataLong(
					longColStats.getLowValue(),
					longColStats.getHighValue(),
					longColStats.getNumDVs(),
					longColStats.getNumNulls());
	} else if (stats.isSetStringStats()) {
		StringColumnStatsData stringStats = stats.getStringStats();
		return new CatalogColumnStatisticsDataString(
				stringStats.getMaxColLen(),
				stringStats.getAvgColLen(),
				stringStats.getNumDVs(),
				stringStats.getNumNulls());
	} else {
		LOG.warn("Flink does not support converting ColumnStatisticsData '{}' for Hive column type '{}' yet.", stats, colType);
		return null;
	}
}
 
Example #11
Source File: HiveStatsUtil.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Convert Flink ColumnStats to Hive ColumnStatisticsData according to Hive column type.
 * Note we currently assume that, in Flink, the max and min of ColumnStats will be same type as the Flink column type.
 * For example, for SHORT and Long columns, the max and min of their ColumnStats should be of type SHORT and LONG.
 */
private static ColumnStatisticsData getColumnStatisticsData(DataType colType, CatalogColumnStatisticsDataBase colStat) {
	LogicalTypeRoot type = colType.getLogicalType().getTypeRoot();
	if (type.equals(LogicalTypeRoot.CHAR)
	|| type.equals(LogicalTypeRoot.VARCHAR)) {
		if (colStat instanceof CatalogColumnStatisticsDataString) {
			CatalogColumnStatisticsDataString stringColStat = (CatalogColumnStatisticsDataString) colStat;
			return ColumnStatisticsData.stringStats(new StringColumnStatsData(stringColStat.getMaxLength(), stringColStat.getAvgLength(), stringColStat.getNullCount(), stringColStat.getNdv()));
		}
	} else if (type.equals(LogicalTypeRoot.BOOLEAN)) {
		if (colStat instanceof CatalogColumnStatisticsDataBoolean) {
			CatalogColumnStatisticsDataBoolean booleanColStat = (CatalogColumnStatisticsDataBoolean) colStat;
			BooleanColumnStatsData boolStats = new BooleanColumnStatsData(
					booleanColStat.getTrueCount(),
					booleanColStat.getFalseCount(),
					booleanColStat.getNullCount());
			return ColumnStatisticsData.booleanStats(boolStats);
		}
	} else if (type.equals(LogicalTypeRoot.TINYINT)
			|| type.equals(LogicalTypeRoot.SMALLINT)
			|| type.equals(LogicalTypeRoot.INTEGER)
			|| type.equals(LogicalTypeRoot.BIGINT)
			|| type.equals(LogicalTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE)
			|| type.equals(LogicalTypeRoot.TIME_WITHOUT_TIME_ZONE)
			|| type.equals(LogicalTypeRoot.TIMESTAMP_WITH_TIME_ZONE)) {
		if (colStat instanceof CatalogColumnStatisticsDataLong) {
			CatalogColumnStatisticsDataLong longColStat = (CatalogColumnStatisticsDataLong) colStat;
			LongColumnStatsData longColumnStatsData = new LongColumnStatsData(longColStat.getNullCount(), longColStat.getNdv());
			longColumnStatsData.setHighValue(longColStat.getMax());
			longColumnStatsData.setLowValue(longColStat.getMin());
			return ColumnStatisticsData.longStats(longColumnStatsData);
		}
	} else if (type.equals(LogicalTypeRoot.FLOAT)
			|| type.equals(LogicalTypeRoot.DOUBLE)) {
		if (colStat instanceof CatalogColumnStatisticsDataDouble) {
			CatalogColumnStatisticsDataDouble doubleColumnStatsData = (CatalogColumnStatisticsDataDouble) colStat;
			DoubleColumnStatsData floatStats = new DoubleColumnStatsData(doubleColumnStatsData.getNullCount(), doubleColumnStatsData.getNdv());
			floatStats.setHighValue(doubleColumnStatsData.getMax());
			floatStats.setLowValue(doubleColumnStatsData.getMin());
			return ColumnStatisticsData.doubleStats(floatStats);
		}
	} else if (type.equals(LogicalTypeRoot.DATE)) {
		if (colStat instanceof CatalogColumnStatisticsDataDate) {
			CatalogColumnStatisticsDataDate dateColumnStatsData = (CatalogColumnStatisticsDataDate) colStat;
			DateColumnStatsData dateStats = new DateColumnStatsData(dateColumnStatsData.getNullCount(), dateColumnStatsData.getNdv());
			dateStats.setHighValue(new org.apache.hadoop.hive.metastore.api.Date(dateColumnStatsData.getMax().getDaysSinceEpoch()));
			dateStats.setLowValue(new org.apache.hadoop.hive.metastore.api.Date(dateColumnStatsData.getMin().getDaysSinceEpoch()));
			return ColumnStatisticsData.dateStats(dateStats);
		}
	} else if (type.equals(LogicalTypeRoot.VARBINARY)
			|| type.equals(LogicalTypeRoot.BINARY)
			|| type.equals(LogicalTypeRoot.BINARY)) {
		if (colStat instanceof CatalogColumnStatisticsDataBinary) {
			CatalogColumnStatisticsDataBinary binaryColumnStatsData = (CatalogColumnStatisticsDataBinary) colStat;
			BinaryColumnStatsData binaryColumnStats = new BinaryColumnStatsData(binaryColumnStatsData.getMaxLength(), binaryColumnStatsData.getAvgLength(), binaryColumnStatsData.getNullCount());
			return ColumnStatisticsData.binaryStats(binaryColumnStats);
		}
	}
	throw new CatalogException(String.format("Flink does not support converting ColumnStats '%s' for Hive column " +
											"type '%s' yet", colStat, colType));
}
 
Example #12
Source File: TestUtils.java    From circus-train with Apache License 2.0 4 votes vote down vote up
public static Table createPartitionedTable(
    HiveMetaStoreClient metaStoreClient,
    String database,
    String table,
    URI location,
    List<FieldSchema> columns,
    List<FieldSchema> partitionKeys,
    String serializationLib,
    String inputFormatClassName,
    String outputFormatClassName)
    throws Exception {

  Table hiveTable = new Table();
  hiveTable.setDbName(database);
  hiveTable.setTableName(table);
  hiveTable.setTableType(TableType.EXTERNAL_TABLE.name());
  hiveTable.putToParameters("EXTERNAL", "TRUE");

  hiveTable.setPartitionKeys(partitionKeys);

  StorageDescriptor sd = new StorageDescriptor();
  sd.setCols(columns);
  sd.setLocation(location.toString());
  sd.setParameters(new HashMap<String, String>());
  sd.setInputFormat(inputFormatClassName);
  sd.setOutputFormat(outputFormatClassName);
  sd.setSerdeInfo(new SerDeInfo());
  sd.getSerdeInfo().setSerializationLib(serializationLib);

  hiveTable.setSd(sd);

  metaStoreClient.createTable(hiveTable);

  ColumnStatisticsDesc statsDesc = new ColumnStatisticsDesc(true, database, table);
  ColumnStatisticsData statsData = new ColumnStatisticsData(_Fields.LONG_STATS, new LongColumnStatsData(1L, 2L));
  ColumnStatisticsObj cso1 = new ColumnStatisticsObj("id", "bigint", statsData);
  List<ColumnStatisticsObj> statsObj = Collections.singletonList(cso1);
  metaStoreClient.updateTableColumnStatistics(new ColumnStatistics(statsDesc, statsObj));

  return hiveTable;
}
 
Example #13
Source File: HiveStatsUtil.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Create Flink ColumnStats from Hive ColumnStatisticsData.
 */
private static CatalogColumnStatisticsDataBase createTableColumnStats(DataType colType, ColumnStatisticsData stats, String hiveVersion) {
	HiveShim hiveShim = HiveShimLoader.loadHiveShim(hiveVersion);
	if (stats.isSetBinaryStats()) {
		BinaryColumnStatsData binaryStats = stats.getBinaryStats();
		return new CatalogColumnStatisticsDataBinary(
				binaryStats.isSetMaxColLen() ? binaryStats.getMaxColLen() : null,
				binaryStats.isSetAvgColLen() ? binaryStats.getAvgColLen() : null,
				binaryStats.isSetNumNulls() ? binaryStats.getNumNulls() : null);
	} else if (stats.isSetBooleanStats()) {
		BooleanColumnStatsData booleanStats = stats.getBooleanStats();
		return new CatalogColumnStatisticsDataBoolean(
				booleanStats.isSetNumTrues() ? booleanStats.getNumTrues() : null,
				booleanStats.isSetNumFalses() ? booleanStats.getNumFalses() : null,
				booleanStats.isSetNumNulls() ? booleanStats.getNumNulls() : null);
	} else if (hiveShim.isDateStats(stats)) {
		return hiveShim.toFlinkDateColStats(stats);
	} else if (stats.isSetDoubleStats()) {
			DoubleColumnStatsData doubleStats = stats.getDoubleStats();
			return new CatalogColumnStatisticsDataDouble(
					doubleStats.isSetLowValue() ? doubleStats.getLowValue() : null,
					doubleStats.isSetHighValue() ? doubleStats.getHighValue() : null,
					doubleStats.isSetNumDVs() ? doubleStats.getNumDVs() : null,
					doubleStats.isSetNumNulls() ? doubleStats.getNumNulls() : null);
	} else if (stats.isSetLongStats()) {
			LongColumnStatsData longColStats = stats.getLongStats();
			return new CatalogColumnStatisticsDataLong(
					longColStats.isSetLowValue() ? longColStats.getLowValue() : null,
					longColStats.isSetHighValue() ? longColStats.getHighValue() : null,
					longColStats.isSetNumDVs() ? longColStats.getNumDVs() : null,
					longColStats.isSetNumNulls() ? longColStats.getNumNulls() : null);
	} else if (stats.isSetStringStats()) {
		StringColumnStatsData stringStats = stats.getStringStats();
		return new CatalogColumnStatisticsDataString(
				stringStats.isSetMaxColLen() ? stringStats.getMaxColLen() : null,
				stringStats.isSetAvgColLen() ? stringStats.getAvgColLen() : null,
				stringStats.isSetNumDVs() ? stringStats.getNumDVs() : null,
				stringStats.isSetNumDVs() ? stringStats.getNumNulls() : null);
	} else if (stats.isSetDecimalStats()) {
		DecimalColumnStatsData decimalStats = stats.getDecimalStats();
		// for now, just return CatalogColumnStatisticsDataDouble for decimal columns
		Double max = null;
		if (decimalStats.isSetHighValue()) {
			max = toHiveDecimal(decimalStats.getHighValue()).doubleValue();
		}
		Double min = null;
		if (decimalStats.isSetLowValue()) {
			min = toHiveDecimal(decimalStats.getLowValue()).doubleValue();
		}
		Long ndv = decimalStats.isSetNumDVs() ? decimalStats.getNumDVs() : null;
		Long nullCount = decimalStats.isSetNumNulls() ? decimalStats.getNumNulls() : null;
		return new CatalogColumnStatisticsDataDouble(min, max, ndv, nullCount);
	} else {
		LOG.warn("Flink does not support converting ColumnStatisticsData '{}' for Hive column type '{}' yet.", stats, colType);
		return null;
	}
}