[fix](LOAD statement): fix bug for toSql func of LoadStmt. (#12648)

This commit is contained in:
wxy
2022-09-22 09:07:46 +08:00
committed by GitHub
parent c58e4ca03b
commit 1ae7c4e307
2 changed files with 7 additions and 4 deletions

View File

@ -917,14 +917,17 @@ public class DataDescription {
if (columnSeparator != null) {
sb.append(" COLUMNS TERMINATED BY ").append(columnSeparator.toSql());
}
if (columnsFromPath != null && !columnsFromPath.isEmpty()) {
sb.append(" COLUMNS FROM PATH AS (");
Joiner.on(", ").appendTo(sb, columnsFromPath).append(")");
if (fileFormat != null && !fileFormat.isEmpty()) {
sb.append(" FORMAT AS '" + fileFormat + "'");
}
if (fileFieldNames != null && !fileFieldNames.isEmpty()) {
sb.append(" (");
Joiner.on(", ").appendTo(sb, fileFieldNames).append(")");
}
if (columnsFromPath != null && !columnsFromPath.isEmpty()) {
sb.append(" COLUMNS FROM PATH AS (");
Joiner.on(", ").appendTo(sb, columnsFromPath).append(")");
}
if (columnMappingList != null && !columnMappingList.isEmpty()) {
sb.append(" SET (");
Joiner.on(", ").appendTo(sb, Lists.transform(columnMappingList, new Function<Expr, Object>() {

View File

@ -128,7 +128,7 @@ public class DataDescriptionTest {
desc = new DataDescription("testTable", null, Lists.newArrayList("abc.txt"),
Lists.newArrayList("col1", "col2"), new Separator(","), "csv", null, false, null, null, whereExpr, LoadTask.MergeType.MERGE, whereExpr, null, null);
desc.analyze("testDb");
Assert.assertEquals("MERGE DATA INFILE ('abc.txt') INTO TABLE testTable COLUMNS TERMINATED BY ',' (col1, col2) WHERE 1 = 1 DELETE ON 1 = 1", desc.toString());
Assert.assertEquals("MERGE DATA INFILE ('abc.txt') INTO TABLE testTable COLUMNS TERMINATED BY ',' FORMAT AS 'csv' (col1, col2) WHERE 1 = 1 DELETE ON 1 = 1", desc.toString());
Assert.assertEquals("1 = 1", desc.getWhereExpr().toSql());
Assert.assertEquals("1 = 1", desc.getDeleteCondition().toSql());
Assert.assertEquals(",", desc.getColumnSeparator());