Github user manishgupta88 commented on a diff in the pull request:
https://github.com/apache/carbondata/pull/2102#discussion_r177395959
--- Diff:
integration/spark2/src/test/scala/org/apache/spark/carbondata/restructure/AlterTableValidationTestCase.scala
---
@@ -584,6 +589,98 @@ test("test alter command for boolean data type with
correct default measure valu
"alter table testalterwithbooleanwithoutdefaultvalue add
columns(booleanfield boolean)")
checkAnswer(sql("select * from
testalterwithbooleanwithoutdefaultvalue"),Seq(Row(1,"anubhav",null)))
}
+ test("test alter command for filter on default values on date datatype")
{
+ sql("drop table if exists test")
+ sql(
+ "create table test(id int,vin string,phonenumber long,area
string,salary int,country " +
+ "string,longdate date) stored by 'carbondata'")
+ sql("insert into test select
1,'String1',12345,'area',20,'country','2017-02-12'")
+ sql("alter table test add columns (c3 date)
TBLPROPERTIES('DEFAULT.VALUE.c3' = '1993-01-01')")
+ sql("insert into test select
2,'String1',12345,'area',20,'country','2017-02-12','1994-01-01'")
+ sql("insert into test select
3,'String1',12345,'area',20,'country','2017-02-12','1995-01-01'")
+ sql("insert into test select
4,'String1',12345,'area',20,'country','2017-02-12','1996-01-01'")
+ checkAnswer(sql("select id from test where c3='1993-01-01'"),
Seq(Row(1)))
+ checkAnswer(sql("select id from test where c3<'1995-01-01'"),
Seq(Row(1), Row(2)))
+ checkAnswer(sql("select id from test where c3>'1994-01-01'"),
Seq(Row(3), Row(4)))
+ checkAnswer(sql("select id from test where c3>='1995-01-01'"),
Seq(Row(3), Row(4)))
+ checkAnswer(sql("select id from test where c3<='1994-01-01'"),
Seq(Row(1), Row(2)))
+ }
+
+ test("test alter command for filter on default values on timestamp
datatype") {
+ def testFilterWithDefaultValue(flag: Boolean) = {
+ CarbonProperties.getInstance()
+ .addProperty(CarbonCommonConstants.CARBON_TIMESTAMP_FORMAT,
+ "yyyy/MM/dd HH:mm:ss")
+ sql("drop table if exists test")
+ sql(
+ "create table test(id int,vin string,phonenumber long,area
string,salary int,country " +
+ "string,longdate date) stored by 'carbondata'")
+ sql("insert into test select
1,'String1',12345,'area',20,'country','2017-02-12'")
+ if (flag) {
+ sql(
+ "alter table test add columns (c3 timestamp)
TBLPROPERTIES('DEFAULT.VALUE.c3' = " +
+ "'1996/01/01 11:11:11', 'DICTIONARY_INCLUDE' = 'c3')")
+ } else {
+ sql(
+ "alter table test add columns (c3 timestamp)
TBLPROPERTIES('DEFAULT.VALUE.c3' = " +
+ "'1996/01/01 11:11:11')")
+ }
+ println("Timestamp Format: " +
CarbonProperties.getInstance().getProperty(CarbonCommonConstants.CARBON_TIMESTAMP_FORMAT))
+ println("flag : "+ flag)
+ sql("select * from test").show(false)
+ sql(
+ "insert into test select
2,'String1',12345,'area',20,'country','2017-02-12','1994/01/01 " +
+ "10:10:10'")
+ sql(
+ "insert into test select
3,'String1',12345,'area',20,'country','2017-02-12','1995/01/01 " +
+ "11:11:11'")
+ sql(
+ "insert into test select
4,'String1',12345,'area',20,'country','2017-02-12','1996/01/01 " +
+ "10:10:10'")
+ checkAnswer(sql("select id from test where c3='1996-01-01
11:11:11'"), Seq(Row(1)))
+ checkAnswer(sql("select id from test where c3<'1995-01-01
11:11:11'"), Seq(Row(2)))
+ checkAnswer(sql("select id from test where c3>'1994-01-02
11:11:11'"),
+ Seq(Row(3), Row(4), Row(1)))
+ checkAnswer(sql("select id from test where c3>='1995-01-01
11:11:11'"),
+ Seq(Row(3), Row(4), Row(1)))
+ checkAnswer(sql("select id from test where c3<='1995-01-02
11:11:11'"), Seq(Row(2),Row(3)))
+ CarbonProperties.getInstance()
+ .addProperty(CarbonCommonConstants.CARBON_TIMESTAMP_FORMAT,
+ CarbonCommonConstants.CARBON_TIMESTAMP_DEFAULT_FORMAT)
+ }
+
+ testFilterWithDefaultValue(false)
+ testFilterWithDefaultValue(true)
+
+ }
+
+ test("test alter command for filter on default values on int") {
+ def testFilterWithDefaultValue(flag: Boolean) = {
+ sql("drop table if exists test")
+ sql(
+ "create table test(id int,vin string,phonenumber long,area
string,salary int,country " +
+ "string,longdate date) stored by 'carbondata'")
+ sql("insert into test select
1,'String1',12345,'area',5000,'country','2017/02/12'")
+ if (flag) {
+ sql(s"alter table test add columns (c3 int)
TBLPROPERTIES('DEFAULT.VALUE.c3' = '23', " +
+ s"'DICTIONARY_INCLUDE'='c3')")
+ } else {
+ sql(s"alter table test add columns (c3 int)
TBLPROPERTIES('DEFAULT.VALUE.c3' = '23')")
+ }
+ sql("insert into test select
2,'String1',12345,'area',5000,'country','2017/02/12',25")
+ sql("insert into test select
3,'String1',12345,'area',5000,'country','2017/02/12',35")
+ sql("insert into test select
4,'String1',12345,'area',5000,'country','2017/02/12',45")
+ checkAnswer(sql("select id from test where c3=23"), Seq(Row(1)))
+ checkAnswer(sql("select id from test where c3<34"), Seq(Row(1),
Row(2)))
+ checkAnswer(sql("select id from test where c3>24"), Seq(Row(2),
Row(3), Row(4)))
+ checkAnswer(sql("select id from test where c3>=35"), Seq(Row(3),
Row(4)))
+ checkAnswer(sql("select id from test where c3<=35"), Seq(Row(1),
Row(2), Row(3)))
--- End diff --
Add a query for !=, null and not null cases also
---