Github user xubo245 commented on a diff in the pull request:

    https://github.com/apache/carbondata/pull/1856#discussion_r174119683
  
    --- Diff: 
integration/spark-common-test/src/test/scala/org/apache/carbondata/integration/spark/testsuite/timeseries/TestTimeSeriesCreateTable.scala
 ---
    @@ -82,149 +92,209 @@ class TestTimeSeriesCreateTable extends QueryTest 
with BeforeAndAfterAll {
            """.stripMargin)
       }
     
    +  override def afterEach(): Unit = {
    +    dropDataMaps("mainTable", "agg1_second", "agg1_minute",
    +      "agg1_hour", "agg1_day", "agg1_month", "agg1_year")
    +  }
    +
       test("test timeseries create table 1") {
         checkExistence(sql("DESCRIBE FORMATTED mainTable_agg0_second"), true, 
"maintable_agg0_second")
    -    sql("drop datamap agg0_second on table mainTable")
    +    sql("DROP DATAMAP agg0_second ON TABLE mainTable")
       }
     
       test("test timeseries create table 2") {
         checkExistence(sql("DESCRIBE FORMATTED mainTable_agg0_hour"), true, 
"maintable_agg0_hour")
    -    sql("drop datamap agg0_hour on table mainTable")
    +    sql("DROP DATAMAP agg0_hour ON TABLE mainTable")
       }
    +
       test("test timeseries create table 3") {
         checkExistence(sql("DESCRIBE FORMATTED maintable_agg0_day"), true, 
"maintable_agg0_day")
    -    sql("drop datamap agg0_day on table mainTable")
    +    sql("DROP DATAMAP agg0_day ON TABLE mainTable")
       }
    +
       test("test timeseries create table 4") {
         checkExistence(sql("DESCRIBE FORMATTED mainTable_agg0_month"), true, 
"maintable_agg0_month")
    -    sql("drop datamap agg0_month on table mainTable")
    +    sql("DROP DATAMAP agg0_month ON TABLE mainTable")
       }
    +
       test("test timeseries create table 5") {
         checkExistence(sql("DESCRIBE FORMATTED mainTable_agg0_year"), true, 
"maintable_agg0_year")
    -    sql("drop datamap agg0_year on table mainTable")
    +    sql("DROP DATAMAP agg0_year ON TABLE mainTable")
       }
     
    -  test("test timeseries create table 6") {
    -    intercept[Exception] {
    +  test("test timeseries create table 6: TIMESERIES should define time 
granularity") {
    +    sql("DROP DATAMAP IF EXISTS agg0_second ON TABLE mainTable")
    +    val e = intercept[MalformedCarbonCommandException] {
           sql(
    -        s"""
    -           | CREATE DATAMAP agg0_second ON TABLE mainTable
    -           | USING '$timeSeries'
    -           | DMPROPERTIES (
    -           | 'EVENT_TIME'='dataTime',
    -           | 'SEC_GRANULARITY'='1')
    -           | AS SELECT dataTime, SUM(age) FROM mainTable
    -           | GROUP BY dataTime
    +        s"""CREATE DATAMAP agg0_second ON TABLE mainTable USING 
'$timeSeries'
    +           |DMPROPERTIES (
    +           |   'event_time'='dataTime',
    +           |   'SEC_GRANULARITY'='1')
    +           |AS SELECT dataTime, SUM(age) FROM mainTable
    +           |GROUP BY dataTime
             """.stripMargin)
         }
    +    assert(e.getMessage.contains("TIMESERIES should define time 
granularity"))
       }
     
    -  test("test timeseries create table 7") {
    -    intercept[Exception] {
    +  test("test timeseries create table 7: Granularity only support 1") {
    +    sql("DROP DATAMAP IF EXISTS agg0_second ON TABLE mainTable")
    +    val e = intercept[MalformedDataMapCommandException] {
           sql(
             s"""
                | CREATE DATAMAP agg0_second ON TABLE mainTable
                | USING '$timeSeries'
                | DMPROPERTIES (
                | 'EVENT_TIME'='dataTime',
    -           | 'SECOND_GRANULARITY'='2')
    +           | 'DAY_GRANULARITY'='1.5')
                | AS SELECT dataTime, SUM(age) FROM mainTable
                | GROUP BY dataTime
            """.stripMargin)
         }
    +    assert(e.getMessage.equals("Granularity only support 1"))
       }
     
    -  test("test timeseries create table 8") {
    -    intercept[Exception] {
    +  test("test timeseries create table 8: Granularity only support 1") {
    +    dropDataMaps("mainTable", "agg1_hour")
    +    val e = intercept[MalformedCarbonCommandException] {
           sql(
    -        s"""
    -           | CREATE DATAMAP agg0_second ON TABLE mainTable
    -           | USING '$timeSeries'
    -           | DMPROPERTIES (
    -           | 'EVENT_TIME'='dataTime',
    -           | 'SECOND_GRANULARITY'='1')
    -           | AS SELECT dataTime, SUM(age) FROM mainTable
    -           | GROUP BY dataTime
    -       """.stripMargin)
    +        s"""CREATE DATAMAP agg1_hour ON TABLE mainTable USING '$timeSeries'
    +           |DMPROPERTIES (
    +           |   'event_time'='dataTime',
    +           |   'HOUR_GRANULARITY'='hour=-2')
    +           |AS SELECT dataTime, SUM(age) FROM mainTable
    +           |GROUP BY dataTime
    +        """.stripMargin)
    +    }
    +    assert(e.getMessage.contains("Granularity only support "))
    +    checkExistence(sql("SHOW DATAMAP ON TABLE mainTable"), false, 
"maintable_agg1_hour")
    +  }
    +
    +  test("test timeseries create table 9: SECOND_GRANULARITY is null") {
    +    sql("DROP DATAMAP IF EXISTS agg1 ON TABLE mainTable")
    +    val e = intercept[MalformedCarbonCommandException] {
           sql(
    -        s"""
    -           | CREATE DATAMAP agg0_second ON TABLE mainTable
    -           | USING '$timeSeries'
    -           | DMPROPERTIES (
    -           | 'EVENT_TIME'='dataTime',
    -           | 'SECOND_GRANULARITY'='1')
    -           | AS SELECT dataTime, SUM(age) FROM mainTable
    -           | GROUP BY dataTime
    -       """.stripMargin)
    +        s"""CREATE DATAMAP agg0_hour ON TABLE mainTable
    +           |USING '$timeSeries'
    +           |DMPROPERTIES (
    +           |   'event_time'='dataTime',
    +           |   'HOUR_GRANULARITY'='')
    +           |AS SELECT dataTime, SUM(age) FROM mainTable
    +           |GROUP BY dataTime
    +        """.stripMargin)
    +    }
    +    assert(e.getMessage.contains("Granularity only support 1"))
    +  }
    +
    +  test("test timeseries create table 10: Table already exists in 
database") {
    +    val e = intercept[MalformedDataMapCommandException] {
    +      sql(
    +        s"""CREATE DATAMAP agg1_hour ON TABLE mainTable USING '$timeSeries'
    +           |DMPROPERTIES (
    +           |   'event_time'='dataTime',
    +           |   'HOUR_GRANULARITY'='1')
    +           |AS SELECT dataTime, SUM(age) FROM mainTable
    +           |GROUP BY dataTime
    +        """.stripMargin)
    +      sql(
    +        s"""CREATE DATAMAP agg1_hour ON TABLE mainTable USING '$timeSeries'
    +           |DMPROPERTIES (
    +           |   'event_time'='dataTime',
    +           |   'HOUR_GRANULARITY'='1')
    +           |AS SELECT dataTime, SUM(age) FROM mainTable
    +           |GROUP BY dataTime
    +        """.stripMargin)
         }
    +    assert(e.getMessage.contains(
    +      "DataMap name 'agg1_hour' already exist"))
       }
     
    -  test("test timeseries create table 9") {
    -    intercept[Exception] {
    +  test("test timeseries create table 11: don't support create timeseries 
table on non timestamp") {
    +    sql("DROP DATAMAP IF EXISTS agg0_hour ON TABLE mainTable")
    +    val e = intercept[MalformedCarbonCommandException] {
           sql(
             s"""
    -           | CREATE DATAMAP agg0_second ON TABLE mainTable
    +           | CREATE DATAMAP agg0_hour ON TABLE mainTable
                | USING '$timeSeries'
                | DMPROPERTIES (
                | 'EVENT_TIME'='name',
    -           | 'SECOND_GRANULARITY'='1')
    +           | 'HOUR_GRANULARITY'='1')
                | AS SELECT dataTime, SUM(age) FROM mainTable
                | GROUP BY dataTime
            """.stripMargin)
         }
    +    assert(e.getMessage.equals("Timeseries event time is only supported on 
Timestamp column"))
       }
     
    -  test("test timeseries create table 10") {
    -    intercept[Exception] {
    +  test("test timeseries create table 12: Time series column dataTime does 
not exists in select") {
    +    sql("DROP DATAMAP IF EXISTS agg0_hour ON TABLE mainTable")
    +    val e = intercept[MalformedCarbonCommandException] {
           sql(
             s"""
    -           | CREATE DATAMAP agg0_second ON TABLE mainTable
    +           | CREATE DATAMAP agg0_hour ON TABLE mainTable
                | USING '$timeSeries'
                | DMPROPERTIES (
    -           | 'EVENT_TIME'='name',
    -           | 'SECOND_GRANULARITY'='1')
    -           | AS SELECT dataTime, SUM(age) FROM mainTable
    -           | GROUP BY dataTime
    -       """.stripMargin)
    +           | 'EVENT_TIME'='dataTime',
    +           | 'HOUR_GRANULARITY'='1')
    +           | AS SELECT name, SUM(age) FROM mainTable
    +           | GROUP BY name
    +         """.stripMargin)
    +    }
    +    assert(e.getMessage.equals("Time series column dataTime does not 
exists in select"))
    +  }
    +
    +  test("test timeseries create table 13: don't support create timeseries 
table on non timestamp") {
    +    sql("DROP DATAMAP IF EXISTS agg0_hour ON TABLE mainTable")
    +    val e = intercept[MalformedCarbonCommandException] {
    +      sql(
    +        s"""CREATE DATAMAP agg0_hour ON TABLE mainTable
    +           |USING '$timeSeries'
    +           |DMPROPERTIES (
    +           |   'event_time'='name',
    +           |   'HOUR_GRANULARITY'='1')
    +           |AS SELECT name, SUM(age) FROM mainTable
    +           |GROUP BY name
    +        """.stripMargin)
         }
    +    assert(e.getMessage.contains("Timeseries event time is only supported 
on Timestamp column"))
       }
     
    -  test("test timeseries create table 11: USING") {
    +  test("test timeseries create table 14: USING") {
         val e: Exception = intercept[MalformedDataMapCommandException] {
           sql(
    -        """CREATE DATAMAP agg1 ON TABLE mainTable
    +        """CREATE DATAMAP agg0_hour ON TABLE mainTable
               | USING 'abc'
               | DMPROPERTIES (
               |   'EVENT_TIME'='dataTime',
    -          |   'SECOND_GRANULARITY'='1')
    +          |   'HOUR_GRANULARITY'='1')
               | AS SELECT dataTime, SUM(age) FROM mainTable
               | GROUP BY dataTime
             """.stripMargin)
         }
         assert(e.getMessage.equals("DataMap 'abc' not found"))
       }
     
    -  test("test timeseries create table 12: USING and catch 
MalformedCarbonCommandException") {
    +  test("test timeseries create table 15: USING and catch 
MalformedCarbonCommandException") {
         val e: Exception = intercept[MalformedCarbonCommandException] {
           sql(
    -        """CREATE DATAMAP agg1 ON TABLE mainTable
    +        """CREATE DATAMAP agg0_hour ON TABLE mainTable
               | USING 'abc'
               | DMPROPERTIES (
               |   'EVENT_TIME'='dataTime',
    -          |   'SECOND_GRANULARITY'='1')
    +          |   'HOUR_GRANULARITY'='1')
               | AS SELECT dataTime, SUM(age) FROM mainTable
               | GROUP BY dataTime
             """.stripMargin)
         }
         assert(e.getMessage.equals("DataMap 'abc' not found"))
       }
     
    -  test("test timeseries create table 13: Only one granularity level can be 
defined 1") {
    -    sql("DROP DATAMAP IF EXISTS agg0_second ON TABLE mainTable")
    +  test("test timeseries create table 16: Only one granularity level can be 
defined 1") {
    +    sql("DROP DATAMAP IF EXISTS agg0_hour ON TABLE mainTable")
         val e: Exception = intercept[MalformedCarbonCommandException] {
           sql(
             s"""
    -           | CREATE DATAMAP agg0_second ON TABLE mainTable
    +           | CREATE DATAMAP agg0_hour ON TABLE mainTable
    --- End diff --
    
    It's unreasonable to create pre-aggregate with second granularity, second 
aggregate is used less than hour in reality life.


---

Reply via email to