Skip to content

Commit

Permalink
Merge 668576f into d3c907b
Browse files Browse the repository at this point in the history
  • Loading branch information
shivamasn committed Dec 13, 2018
2 parents d3c907b + 668576f commit b809de8
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,31 @@ class TestComplexDataType extends QueryTest with BeforeAndAfterAll {
Seq(Row(1, "abc", Row(mutable.WrappedArray.make(Array("abc", "bcd"))), "bcd")))
}

test("test Projection PushDown for Array - String type when Array is Empty") {
CarbonProperties.getInstance()
.addProperty(CarbonCommonConstants.CARBON_BAD_RECORDS_ACTION, "FAIL")
sql("drop table if exists table1")
sql("create table table1 (detail array<string>) stored by 'carbondata'")
sql("insert into table1 values('')")
checkAnswer(sql("select detail[0] from table1"), Seq(Row("")))
sql("drop table if exists table1")
CarbonProperties.getInstance()
.addProperty(CarbonCommonConstants.CARBON_BAD_RECORDS_ACTION, badRecordAction)
}

test("test Projection PushDown for Struct - Array type when Array is Empty") {
CarbonProperties.getInstance()
.addProperty(CarbonCommonConstants.CARBON_BAD_RECORDS_ACTION, "FAIL")
sql("drop table if exists table1")
sql("create table table1 (person struct<detail:array<string>,age:int>) stored by 'carbondata'")
sql("insert into table1 values ('$1')")
checkAnswer(sql("select person.detail[0] from table1"), Seq(Row("")))
checkAnswer(sql("select person.age from table1"), Seq(Row(1)))
sql("drop table if exists table1")
CarbonProperties.getInstance()
.addProperty(CarbonCommonConstants.CARBON_BAD_RECORDS_ACTION, badRecordAction)
}

test("test Projection PushDown for Struct - Double type") {
sql("DROP TABLE IF EXISTS table1")
sql(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public ArrayObject parse(Object data) {
}
return new ArrayObject(array);
}
} else if (value.isEmpty()) {
Object[] array = new Object[1];
array[0] = value;
return new ArrayObject(array);
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2072,4 +2072,36 @@ public void testReadingNullValues() {
}
}

@Test
public void testSdkWriteWhenArrayOfStringIsEmpty() throws IOException, InvalidLoadOptionException {
String badRecordAction =
CarbonProperties.getInstance().getProperty(CarbonCommonConstants.CARBON_BAD_RECORDS_ACTION);
CarbonProperties.getInstance()
.addProperty(CarbonCommonConstants.CARBON_BAD_RECORDS_ACTION, "FAIL");

String path = "./testSdkWriteWhenArrayOfStringIsEmpty";
String[] rec = { "aaa", "bbb", "aaa@cdf.com", "", "", "mmm", "" };
Field[] fields = new Field[7];
fields[0] = new Field("stringField", DataTypes.STRING);
fields[1] = new Field("varcharField", DataTypes.VARCHAR);
fields[2] = new Field("stringField1", DataTypes.STRING);
fields[3] = new Field("arrayField", DataTypes.createArrayType(DataTypes.STRING));
fields[4] = new Field("arrayField1", DataTypes.createArrayType(DataTypes.STRING));
fields[5] = new Field("arrayField2", DataTypes.createArrayType(DataTypes.STRING));
fields[6] = new Field("varcharField1", DataTypes.VARCHAR);
Schema schema = new Schema(fields);
Map map = new HashMap();
map.put("complex_delimiter_level_1", "#");
map.put("bad_records_logger_enable", "TRUE");
map.put("bad_record_path", path + "/badrec");
CarbonWriterBuilder builder = CarbonWriter.builder().outputPath(path);
builder.withLoadOptions(map).withCsvInput(schema).enableLocalDictionary(false)
.writtenBy("CarbonReaderTest");
CarbonWriter writer = builder.build();
writer.write(rec);
writer.close();
CarbonProperties.getInstance()
.addProperty(CarbonCommonConstants.CARBON_BAD_RECORDS_ACTION, badRecordAction);
}

}

0 comments on commit b809de8

Please sign in to comment.