Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRILL-7741: Columns are missing when using convert_from function #2081

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,16 @@ protected IterOutcome handleNullInput() {
return IterOutcome.OK_NEW_SCHEMA;
}

@Override
protected IterOutcome getFinalOutcome(boolean hasMoreRecordInBoundary) {
// In a case of complex writers vectors are added at runtime, so the schema
// may change (e.g. when a batch contains new column(s) not present in previous batches)
if (complexWriters != null) {
return IterOutcome.OK_NEW_SCHEMA;
}
return super.getFinalOutcome(hasMoreRecordInBoundary);
}

private void setupNewSchema(RecordBatch incomingBatch, int configuredBatchSize) {
memoryManager = new ProjectMemoryManager(configuredBatchSize);
memoryManager.init(incomingBatch, ProjectRecordBatch.this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -782,4 +782,26 @@ public void testUntypedPathWithUnion() throws Exception {
resetSessionOption(ExecConstants.ENABLE_UNION_TYPE_KEY);
}
}

@Test
public void testConvertFromJson() throws Exception {
String fileName = "table.tsv";
try (BufferedWriter writer = new BufferedWriter(new FileWriter(new File(dirTestWatcher.getRootDir(), fileName)))) {
for (int i = 0; i < JSONRecordReader.DEFAULT_ROWS_PER_BATCH; i++) {
writer.write("{\"id\":\"1\"}\n");
}
writer.write("{\"id\":\"2\",\"v\":[\"abc\"]}");
}

String sql = "SELECT t.m.id AS id, t.m.v[0] v FROM \n" +
"(SELECT convert_from(columns[0], 'json') AS m FROM dfs.`%s`) t\n" +
"where t.m.id='2'";

testBuilder()
.sqlQuery(sql, fileName)
.unOrdered()
.baselineColumns("id", "v")
.baselineValues("2", "abc")
.go();
}
}