drill-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vvysotskyi <...@git.apache.org>
Subject [GitHub] drill pull request #904: DRILL-5717: change some date time test cases with s...
Date Wed, 08 Nov 2017 09:44:47 GMT
Github user vvysotskyi commented on a diff in the pull request:

    https://github.com/apache/drill/pull/904#discussion_r149612076
  
    --- Diff: exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestDateFunctions.java
---
    @@ -33,128 +33,140 @@
     import org.apache.drill.exec.server.Drillbit;
     import org.apache.drill.exec.server.RemoteServiceSet;
     import org.apache.drill.exec.vector.ValueVector;
    +import org.joda.time.DateTimeUtils;
     import org.joda.time.LocalDate;
    -import org.joda.time.LocalTime;
     import org.joda.time.LocalDateTime;
    +import org.joda.time.LocalTime;
     import org.junit.Ignore;
     import org.junit.Test;
    -
    -import com.google.common.base.Charsets;
    -import com.google.common.io.Files;
     import org.junit.experimental.categories.Category;
    +import org.junit.runner.RunWith;
    +import java.text.DateFormatSymbols;
    +import java.util.List;
    +import java.util.Locale;
    +import static org.junit.Assert.assertEquals;
    +import static org.junit.Assert.assertTrue;
     
    +@RunWith(JMockit.class)
     @Category({UnlikelyTest.class, SqlFunctionTest.class})
     public class TestDateFunctions extends PopUnitTestBase {
    -    static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestDateFunctions.class);
    +  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestDateFunctions.class);
     
    -    public void testCommon(String[] expectedResults, String physicalPlan, String resourceFile)
throws Exception {
    -        try (RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();
    -             Drillbit bit = new Drillbit(CONFIG, serviceSet);
    -             DrillClient client = new DrillClient(CONFIG, serviceSet.getCoordinator()))
{
     
    -            // run query.
    -            bit.run();
    -            client.connect();
    -            List<QueryDataBatch> results = client.runQuery(org.apache.drill.exec.proto.UserBitShared.QueryType.PHYSICAL,
    -                    Files.toString(FileUtils.getResourceAsFile(physicalPlan), Charsets.UTF_8)
    -                            .replace("#{TEST_FILE}", resourceFile));
    +  public void testCommon(String[] expectedResults, String physicalPlan, String resourceFile)
throws Exception {
    +    try (RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();
    +         Drillbit bit = new Drillbit(CONFIG, serviceSet);
    +         DrillClient client = new DrillClient(CONFIG, serviceSet.getCoordinator())) {
     
    -            RecordBatchLoader batchLoader = new RecordBatchLoader(bit.getContext().getAllocator());
    +      // run query.
    +      bit.run();
    +      client.connect();
    +      List<QueryDataBatch> results = client.runQuery(org.apache.drill.exec.proto.UserBitShared.QueryType.PHYSICAL,
    +        Files.toString(FileUtils.getResourceAsFile(physicalPlan), Charsets.UTF_8)
    +          .replace("#{TEST_FILE}", resourceFile));
     
    -            QueryDataBatch batch = results.get(0);
    -            assertTrue(batchLoader.load(batch.getHeader().getDef(), batch.getData()));
    +      RecordBatchLoader batchLoader = new RecordBatchLoader(bit.getContext().getAllocator());
     
    +      QueryDataBatch batch = results.get(0);
    +      assertTrue(batchLoader.load(batch.getHeader().getDef(), batch.getData()));
     
    -            int i = 0;
    -            for (VectorWrapper<?> v : batchLoader) {
     
    -                ValueVector.Accessor accessor = v.getValueVector().getAccessor();
    -                System.out.println(accessor.getObject(0));
    -                assertEquals( expectedResults[i++], accessor.getObject(0).toString());
    -            }
    -
    -            batchLoader.clear();
    -            for(QueryDataBatch b : results){
    -                b.release();
    -            }
    -        }
    -    }
    -
    -    @Test
    -    @Ignore("relies on particular timezone")
    -    public void testDateIntervalArithmetic() throws Exception {
    -        String expectedResults[] = {"2009-02-23T00:00:00.000-08:00",
    -                                    "2008-02-24T00:00:00.000-08:00",
    -                                    "1970-01-01T13:20:33.000-08:00",
    -                                    "2008-02-24T12:00:00.000-08:00",
    -                                    "2009-04-23T12:00:00.000-07:00",
    -                                    "2008-02-24T12:00:00.000-08:00",
    -                                    "2009-04-23T12:00:00.000-07:00",
    -                                    "2009-02-23T00:00:00.000-08:00",
    -                                    "2008-02-24T00:00:00.000-08:00",
    -                                    "1970-01-01T13:20:33.000-08:00",
    -                                    "2008-02-24T12:00:00.000-08:00",
    -                                    "2009-04-23T12:00:00.000-07:00",
    -                                    "2008-02-24T12:00:00.000-08:00",
    -                                    "2009-04-23T12:00:00.000-07:00"};
    -        testCommon(expectedResults, "/functions/date/date_interval_arithmetic.json",
"/test_simple_date.json");
    -    }
    -
    -    @Test
    -    public void testDateDifferenceArithmetic() throws Exception {
    -
    -        String[] expectedResults = {"P365D",
    -                                    "P-366DT-60S",
    -                                    "PT39600S"};
    -        testCommon(expectedResults, "/functions/date/date_difference_arithmetic.json",
"/test_simple_date.json");
    -    }
    -
    -    @Test
    -    public void testAge() throws Exception {
    -        String[] expectedResults = { "P109M16DT82800S",
    -                                     "P172M27D",
    -                                     "P-172M-27D",
    -                                     "P-39M-18DT-63573S"};
    -        testCommon(expectedResults, "/functions/date/age.json", "/test_simple_date.json");
    -    }
    -
    -    @Test
    -    public void testIntervalArithmetic() throws Exception {
    -
    -      String expectedResults[] = {"P2Y2M",
    -          "P2DT3723S",
    -          "P2M",
    -          "PT3723S",
    -          "P28M",
    -          "PT7206S",
    -          "P7M",
    -          "PT1801.500S",
    -          "P33M18D",
    -          "PT8647.200S",
    -          "P6M19DT86399.999S",
    -          "PT1715.714S"};
    -
    -        testCommon(expectedResults, "/functions/date/interval_arithmetic.json", "/test_simple_date.json");
    -    }
    -
    -    @Test
    -    public void testToChar() throws Exception {
    -
    -        String expectedResults[] = {(new LocalDate(2008, 2, 23)).toString("yyyy-MMM-dd"),
    -                                    (new LocalTime(12, 20, 30)).toString("HH mm ss"),
    -                                    (new LocalDateTime(2008, 2, 23, 12, 0, 0)).toString("yyyy
MMM dd HH:mm:ss")};
    -        testCommon(expectedResults, "/functions/date/to_char.json", "/test_simple_date.json");
    -    }
    +      int i = 0;
    +      for (VectorWrapper<?> v : batchLoader) {
     
    -    @Test
    -    @Ignore("relies on particular time zone")
    -    public void testToDateType() throws Exception {
    -        String expectedResults[] = {"2008-02-23T00:00:00.000-08:00",
    -                                    "1970-01-01T12:20:30.000-08:00",
    -                                    "2008-02-23T12:00:00.000-08:00",
    -                                    "2008-02-23T12:00:00.000-08:00"};
    +        ValueVector.Accessor accessor = v.getValueVector().getAccessor();
    +        System.out.println(accessor.getObject(0));
    +        assertEquals(expectedResults[i++], accessor.getObject(0).toString());
    +      }
     
    -        testCommon(expectedResults, "/functions/date/to_date_type.json", "/test_simple_date.json");
    +      batchLoader.clear();
    +      for (QueryDataBatch b : results) {
    +        b.release();
    +      }
         }
    +  }
    +
    +  @Test
    +  @Ignore("relies on particular timezone")
    +  public void testDateIntervalArithmetic() throws Exception {
    +    String expectedResults[] = {"2009-02-23T00:00:00.000-08:00",
    +                                "2008-02-24T00:00:00.000-08:00",
    +                                "1970-01-01T13:20:33.000-08:00",
    +                                "2008-02-24T12:00:00.000-08:00",
    +                                "2009-04-23T12:00:00.000-07:00",
    +                                "2008-02-24T12:00:00.000-08:00",
    +                                "2009-04-23T12:00:00.000-07:00",
    +                                "2009-02-23T00:00:00.000-08:00",
    +                                "2008-02-24T00:00:00.000-08:00",
    +                                "1970-01-01T13:20:33.000-08:00",
    +                                "2008-02-24T12:00:00.000-08:00",
    +                                "2009-04-23T12:00:00.000-07:00",
    +                                "2008-02-24T12:00:00.000-08:00",
    +                                "2009-04-23T12:00:00.000-07:00"};
    +    testCommon(expectedResults, "/functions/date/date_interval_arithmetic.json", "/test_simple_date.json");
    +  }
    +
    +  @Test
    +  public void testDateDifferenceArithmetic() throws Exception {
    +
    +    String[] expectedResults = {"P365D",
    +                                "P-366DT-60S",
    +                                "PT39600S"};
    +    testCommon(expectedResults, "/functions/date/date_difference_arithmetic.json", "/test_simple_date.json");
    +  }
    +
    +  @Test
    +  public void testAge() throws Exception {
    +    String[] expectedResults = {"P109M16DT82800S",
    +                                "P172M27D",
    +                                "P-172M-27D",
    +                                "P-39M-18DT-63573S"};
    +    testCommon(expectedResults, "/functions/date/age.json", "/test_simple_date.json");
    +  }
    +
    +  @Test
    +  public void testIntervalArithmetic() throws Exception {
    +
    +    String expectedResults[] = {"P2Y2M",
    +                                "P2DT3723S",
    +                                "P2M",
    +                                "PT3723S",
    +                                "P28M",
    +                                "PT7206S",
    +                                "P7M",
    +                                "PT1801.500S",
    +                                "P33M18D",
    +                                "PT8647.200S",
    +                                "P6M19DT86399.999S",
    +                                "PT1715.714S"};
    +
    +    testCommon(expectedResults, "/functions/date/interval_arithmetic.json", "/test_simple_date.json");
    +  }
    +
    +  @Test
    +  public void testToChar() throws Exception {
    +    new MockUp<DateTimeUtils>() {
    --- End diff --
    
    Please replace this mock by method


---

Mime
View raw message