@Test
 public void testDatePartition() {
   PartitionDesc partitionDesc = new PartitionDesc();
   partitionDesc.setPartitionDateColumn("DEFAULT.TABLE_NAME.DATE_COLUMN");
   partitionDesc.setPartitionDateFormat("yyyy-MM-dd");
   String condition =
       partitionConditionBuilder.buildDateRangeCondition(
           partitionDesc,
           DateFormat.stringToMillis("2016-02-22"),
           DateFormat.stringToMillis("2016-02-23"),
           new HashMap<String, String>());
   Assert.assertEquals(
       "DEFAULT.TABLE_NAME.DATE_COLUMN >= '2016-02-22' AND DEFAULT.TABLE_NAME.DATE_COLUMN < '2016-02-23'",
       condition);
 }
 @Test
 public void testTimePartition() {
   PartitionDesc partitionDesc = new PartitionDesc();
   partitionDesc.setPartitionTimeColumn("DEFAULT.TABLE_NAME.HOUR_COLUMN");
   partitionDesc.setPartitionTimeFormat("HH");
   String condition =
       partitionConditionBuilder.buildDateRangeCondition(
           partitionDesc,
           DateFormat.stringToMillis(
               "2016-02-22 00:00:00", DateFormat.DEFAULT_DATETIME_PATTERN_WITHOUT_MILLISECONDS),
           DateFormat.stringToMillis(
               "2016-02-23 01:00:00", DateFormat.DEFAULT_DATETIME_PATTERN_WITHOUT_MILLISECONDS),
           new HashMap<String, String>());
   Assert.assertEquals(
       "DEFAULT.TABLE_NAME.HOUR_COLUMN >= '00' AND DEFAULT.TABLE_NAME.HOUR_COLUMN < '01'",
       condition);
 }
Esempio n. 3
0
  @Override
  protected int getIdFromValueImpl(String value, int roundingFlag) {
    long millis = DateFormat.stringToMillis(value);
    long seconds = millis / 1000;

    if (seconds > MAX_ID) {
      return nullId();
    } else if (seconds < 0) {
      throw new IllegalArgumentException(
          "Illegal value: " + value + ", parsed seconds: " + seconds);
    }

    return (int) seconds;
  }
 @Test
 public void testDateAndTimePartitionWithAlias() {
   PartitionDesc partitionDesc = new PartitionDesc();
   partitionDesc.setPartitionDateColumn("TABLE_ALIAS.DATE_COLUMN");
   partitionDesc.setPartitionDateFormat("yyyy-MM-dd");
   partitionDesc.setPartitionTimeColumn("TABLE_ALIAS.HOUR_COLUMN");
   partitionDesc.setPartitionTimeFormat("H");
   String condition =
       partitionConditionBuilder.buildDateRangeCondition(
           partitionDesc,
           DateFormat.stringToMillis(
               "2016-02-22 00:00:00", DateFormat.DEFAULT_DATETIME_PATTERN_WITHOUT_MILLISECONDS),
           DateFormat.stringToMillis(
               "2016-02-23 01:00:00", DateFormat.DEFAULT_DATETIME_PATTERN_WITHOUT_MILLISECONDS),
           new HashMap<String, String>() {
             {
               put("TABLE_ALIAS", "DEFAULT.TABLE_NAME");
             }
           });
   Assert.assertEquals(
       "DEFAULT.TABLE_NAME.DATE_COLUMN >= '2016-02-22' AND DEFAULT.TABLE_NAME.DATE_COLUMN < '2016-02-23' AND DEFAULT.TABLE_NAME.HOUR_COLUMN >= '0' AND DEFAULT.TABLE_NAME.HOUR_COLUMN < '1'",
       condition);
 }