adarshsanjeev commented on code in PR #16572:
URL: https://github.com/apache/druid/pull/16572#discussion_r1633422793
##########
extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQExportTest.java:
##########
@@ -133,7 +133,142 @@ public void testNumberOfRowsPerFile()
Assert.assertEquals(
expectedFooFileContents(false).size() + 1, // + 1 for the manifest file
- Objects.requireNonNull(new
File(exportDir.getAbsolutePath()).listFiles()).length
+ Objects.requireNonNull(exportDir.listFiles()).length
+ );
+ }
+
+ @Test
+ void testExportComplexColumns() throws IOException
+ {
+ final RowSignature rowSignature = RowSignature.builder()
+ .add("__time",
ColumnType.LONG)
+ .add("a", ColumnType.LONG)
+ .add("b", ColumnType.LONG)
+ .add("c_json",
ColumnType.STRING).build();
+
+ final File exportDir = newTempFolder("export");
+ final String sql = StringUtils.format("INSERT INTO\n"
+ + "EXTERN(local(exportPath=>'%s'))\n"
+ + "AS CSV\n"
+ + "SELECT\n"
+ + " \"a\",\n"
+ + " \"b\",\n"
+ + " json_object(key 'c' value b)
c_json\n"
+ + "FROM (\n"
+ + " SELECT *\n"
+ + " FROM TABLE(\n"
+ + " EXTERN(\n"
+ + "
'{\"type\":\"inline\",\"data\":\"a,b\\n1,1\\n2,2\"}',\n"
+ + "
'{\"type\":\"csv\",\"findColumnsFromHeader\":true}'\n"
+ + " )\n"
+ + " ) EXTEND (\"a\" BIGINT, \"b\"
BIGINT)\n"
+ + ")", exportDir.getAbsolutePath());
+
+ testIngestQuery().setSql(sql)
+ .setExpectedDataSource("foo1")
+ .setQueryContext(DEFAULT_MSQ_CONTEXT)
+ .setExpectedRowSignature(rowSignature)
+ .setExpectedSegment(ImmutableSet.of())
+ .setExpectedResultRows(ImmutableList.of())
+ .verifyResults();
+
+ Assert.assertEquals(
+ 2, // result file and manifest file
+ Objects.requireNonNull(exportDir.listFiles()).length
+ );
+
+ File resultFile = new File(exportDir,
"query-test-query-worker0-partition0.csv");
+ List<String> results = readResultsFromFile(resultFile);
+ Assert.assertEquals(
+ ImmutableList.of(
+ "a,b,c_json", "1,1,\"{\"\"c\"\":1}\"", "2,2,\"{\"\"c\"\":2}\""
Review Comment:
The multiple double quotes for complex columns looked weird to me at first,
but this is because the default escape character for CSV is a double quotes as
well. The values here are consistent with other places we print results in CSV,
like async queries.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]