Search in sources :

Example 1 with DruidQueryBasedInputFormat

use of org.apache.hadoop.hive.druid.io.DruidQueryBasedInputFormat in project hive by apache.

the class TestHiveDruidQueryBasedInputFormat method testTimeZone.

@Test
public void testTimeZone() throws Exception {
    DruidQueryBasedInputFormat input = new DruidQueryBasedInputFormat();
    Method method1 = DruidQueryBasedInputFormat.class.getDeclaredMethod("getInputSplits", Configuration.class);
    method1.setAccessible(true);
    // Create, initialize, and test
    Configuration conf = createPropertiesQuery("sample_datasource", Query.TIMESERIES, TIMESERIES_QUERY);
    HiveDruidSplit[] resultSplits = (HiveDruidSplit[]) method1.invoke(input, conf);
    assertEquals(TIMESERIES_QUERY_SPLIT, Arrays.toString(resultSplits));
    conf = createPropertiesQuery("sample_datasource", Query.TOPN, TOPN_QUERY);
    resultSplits = (HiveDruidSplit[]) method1.invoke(input, conf);
    assertEquals(TOPN_QUERY_SPLIT, Arrays.toString(resultSplits));
    conf = createPropertiesQuery("sample_datasource", Query.GROUP_BY, GROUP_BY_QUERY);
    resultSplits = (HiveDruidSplit[]) method1.invoke(input, conf);
    assertEquals(GROUP_BY_QUERY_SPLIT, Arrays.toString(resultSplits));
}
Also used : HiveDruidSplit(org.apache.hadoop.hive.druid.io.HiveDruidSplit) Configuration(org.apache.hadoop.conf.Configuration) Method(java.lang.reflect.Method) DruidQueryBasedInputFormat(org.apache.hadoop.hive.druid.io.DruidQueryBasedInputFormat) Test(org.junit.Test)

Example 2 with DruidQueryBasedInputFormat

use of org.apache.hadoop.hive.druid.io.DruidQueryBasedInputFormat in project hive by apache.

the class TestHiveDruidQueryBasedInputFormat method testCreateSplitsIntervals.

@SuppressWarnings("unchecked")
@Test
public void testCreateSplitsIntervals() throws Exception {
    DruidQueryBasedInputFormat input = new DruidQueryBasedInputFormat();
    Method method1 = DruidQueryBasedInputFormat.class.getDeclaredMethod("createSplitsIntervals", List.class, int.class);
    method1.setAccessible(true);
    List<Interval> intervals;
    List<List<Interval>> resultList;
    List<List<Interval>> expectedResultList;
    // Test 1 : single split, create 4
    intervals = new ArrayList<>();
    intervals.add(new Interval(1262304000000L, 1293840000000L, ISOChronology.getInstanceUTC()));
    resultList = (List<List<Interval>>) method1.invoke(input, intervals, 4);
    expectedResultList = new ArrayList<>();
    expectedResultList.add(Arrays.asList(new Interval(1262304000000L, 1270188000000L, ISOChronology.getInstanceUTC())));
    expectedResultList.add(Arrays.asList(new Interval(1270188000000L, 1278072000000L, ISOChronology.getInstanceUTC())));
    expectedResultList.add(Arrays.asList(new Interval(1278072000000L, 1285956000000L, ISOChronology.getInstanceUTC())));
    expectedResultList.add(Arrays.asList(new Interval(1285956000000L, 1293840000000L, ISOChronology.getInstanceUTC())));
    assertEquals(expectedResultList, resultList);
    // Test 2 : two splits, create 4
    intervals = new ArrayList<>();
    intervals.add(new Interval(1262304000000L, 1293840000000L, ISOChronology.getInstanceUTC()));
    intervals.add(new Interval(1325376000000L, 1356998400000L, ISOChronology.getInstanceUTC()));
    resultList = (List<List<Interval>>) method1.invoke(input, intervals, 4);
    expectedResultList = new ArrayList<>();
    expectedResultList.add(Arrays.asList(new Interval(1262304000000L, 1278093600000L, ISOChronology.getInstanceUTC())));
    expectedResultList.add(Arrays.asList(new Interval(1278093600000L, 1293840000000L, ISOChronology.getInstanceUTC()), new Interval(1325376000000L, 1325419200000L, ISOChronology.getInstanceUTC())));
    expectedResultList.add(Arrays.asList(new Interval(1325419200000L, 1341208800000L, ISOChronology.getInstanceUTC())));
    expectedResultList.add(Arrays.asList(new Interval(1341208800000L, 1356998400000L, ISOChronology.getInstanceUTC())));
    assertEquals(expectedResultList, resultList);
    // Test 3 : two splits, create 5
    intervals = new ArrayList<>();
    intervals.add(new Interval(1262304000000L, 1293840000000L, ISOChronology.getInstanceUTC()));
    intervals.add(new Interval(1325376000000L, 1356998400000L, ISOChronology.getInstanceUTC()));
    resultList = (List<List<Interval>>) method1.invoke(input, intervals, 5);
    expectedResultList = new ArrayList<>();
    expectedResultList.add(Arrays.asList(new Interval(1262304000000L, 1274935680000L, ISOChronology.getInstanceUTC())));
    expectedResultList.add(Arrays.asList(new Interval(1274935680000L, 1287567360000L, ISOChronology.getInstanceUTC())));
    expectedResultList.add(Arrays.asList(new Interval(1287567360000L, 1293840000000L, ISOChronology.getInstanceUTC()), new Interval(1325376000000L, 1331735040000L, ISOChronology.getInstanceUTC())));
    expectedResultList.add(Arrays.asList(new Interval(1331735040000L, 1344366720000L, ISOChronology.getInstanceUTC())));
    expectedResultList.add(Arrays.asList(new Interval(1344366720000L, 1356998400000L, ISOChronology.getInstanceUTC())));
    assertEquals(expectedResultList, resultList);
    // Test 4 : three splits, different ranges, create 6
    intervals = new ArrayList<>();
    intervals.add(new Interval(1199145600000L, 1201824000000L, ISOChronology.getInstanceUTC()));
    // one month
    intervals.add(new Interval(1325376000000L, 1356998400000L, ISOChronology.getInstanceUTC()));
    // one year
    intervals.add(new Interval(1407283200000L, 1407888000000L, ISOChronology.getInstanceUTC()));
    // 7 days
    resultList = (List<List<Interval>>) method1.invoke(input, intervals, 6);
    expectedResultList = new ArrayList<>();
    expectedResultList.add(Arrays.asList(new Interval(1199145600000L, 1201824000000L, ISOChronology.getInstanceUTC()), new Interval(1325376000000L, 1328515200000L, ISOChronology.getInstanceUTC())));
    expectedResultList.add(Arrays.asList(new Interval(1328515200000L, 1334332800000L, ISOChronology.getInstanceUTC())));
    expectedResultList.add(Arrays.asList(new Interval(1334332800000L, 1340150400000L, ISOChronology.getInstanceUTC())));
    expectedResultList.add(Arrays.asList(new Interval(1340150400000L, 1345968000000L, ISOChronology.getInstanceUTC())));
    expectedResultList.add(Arrays.asList(new Interval(1345968000000L, 1351785600000L, ISOChronology.getInstanceUTC())));
    expectedResultList.add(Arrays.asList(new Interval(1351785600000L, 1356998400000L, ISOChronology.getInstanceUTC()), new Interval(1407283200000L, 1407888000000L, ISOChronology.getInstanceUTC())));
    assertEquals(expectedResultList, resultList);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) Method(java.lang.reflect.Method) DruidQueryBasedInputFormat(org.apache.hadoop.hive.druid.io.DruidQueryBasedInputFormat) Interval(org.joda.time.Interval) Test(org.junit.Test)

Aggregations

Method (java.lang.reflect.Method)2 DruidQueryBasedInputFormat (org.apache.hadoop.hive.druid.io.DruidQueryBasedInputFormat)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Configuration (org.apache.hadoop.conf.Configuration)1 HiveDruidSplit (org.apache.hadoop.hive.druid.io.HiveDruidSplit)1 Interval (org.joda.time.Interval)1