This is an automated email from the ASF dual-hosted git repository. morningman pushed a commit to branch branch-0.15 in repository https://gitbox.apache.org/repos/asf/incubator-doris.git
commit 0c9749c164756f69fa01ab05f5526be20d39a893 Author: Mingyu Chen <[email protected]> AuthorDate: Wed Oct 13 11:44:01 2021 +0800 [Bug] Select outfile failed after query stmt being rewritten. (#6816) --- .../org/apache/doris/analysis/OutFileClause.java | 12 +++++++ .../org/apache/doris/planner/QueryPlanTest.java | 37 ++++++++++++++++++---- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/OutFileClause.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/OutFileClause.java index 248ffd3..18bfc2d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/OutFileClause.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/OutFileClause.java @@ -118,16 +118,20 @@ public class OutFileClause { private List<List<String>> schema = new ArrayList<>(); private Map<String, String> fileProperties = new HashMap<>(); + private boolean isAnalyzed = false; + public OutFileClause(String filePath, String format, Map<String, String> properties) { this.filePath = filePath; this.format = Strings.isNullOrEmpty(format) ? "csv" : format.toLowerCase(); this.properties = properties; + this.isAnalyzed = false; } public OutFileClause(OutFileClause other) { this.filePath = other.filePath; this.format = other.format; this.properties = other.properties == null ? null : Maps.newHashMap(other.properties); + this.isAnalyzed = other.isAnalyzed; } public String getColumnSeparator() { @@ -155,6 +159,13 @@ public class OutFileClause { } private void analyze(Analyzer analyzer) throws UserException { + if (isAnalyzed) { + // If the query stmt is rewritten, the whole stmt will be analyzed again. + // But some of fields in this OutfileClause has been changed, + // such as `filePath`'s schema header has been removed. + // So OutfileClause does not support to be analyzed again. + return; + } analyzeFilePath(); switch (this.format) { @@ -175,6 +186,7 @@ public class OutFileClause { } else if (brokerDesc == null && !isLocalOutput) { throw new AnalysisException("Must specify BROKER properties in OUTFILE clause"); } + isAnalyzed = true; } public void analyze(Analyzer analyzer, SelectStmt stmt) throws UserException { diff --git a/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java b/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java index 1f279b1..31607c5 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java @@ -37,6 +37,7 @@ import org.apache.doris.catalog.Partition; import org.apache.doris.catalog.Replica; import org.apache.doris.catalog.Tablet; import org.apache.doris.catalog.Type; +import org.apache.doris.common.Config; import org.apache.doris.common.FeConstants; import org.apache.doris.common.jmockit.Deencapsulation; import org.apache.doris.load.EtlJobType; @@ -44,19 +45,18 @@ import org.apache.doris.qe.ConnectContext; import org.apache.doris.qe.QueryState.MysqlStateType; import org.apache.doris.utframe.UtFrameUtils; -import org.apache.commons.lang3.StringUtils; - import com.google.common.collect.Lists; -import java.io.File; -import java.util.List; -import java.util.UUID; - +import org.apache.commons.lang3.StringUtils; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; +import java.io.File; +import java.util.List; +import java.util.UUID; + public class QueryPlanTest { // use a unique dir so that it won't be conflict with other unit test which // may also start a Mocked Frontend @@ -1774,4 +1774,29 @@ public class QueryPlanTest { String explainString10 = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql10); Assert.assertTrue(explainString10.contains("PREDICATES: `query_time` = 0")); } + + @Test + public void testOutfile() throws Exception { + connectContext.setDatabase("default_cluster:test"); + Config.enable_outfile_to_local = true; + createTable("CREATE TABLE test.`outfile1` (\n" + + " `date` date NOT NULL,\n" + + " `road_code` int(11) NOT NULL DEFAULT \"-1\"\n" + + ") ENGINE=OLAP\n" + + "DUPLICATE KEY(`date`, `road_code`)\n" + + "COMMENT \"OLAP\"\n" + + "PARTITION BY RANGE(`date`)\n" + + "(PARTITION v2x_ads_lamp_source_percent_statistic_20210929 VALUES [('2021-09-29'), ('2021-09-30')))\n" + + "DISTRIBUTED BY HASH(`road_code`) BUCKETS 1\n" + + "PROPERTIES (\n" + + "\"replication_num\" = \"1\"\n" + + ");"); + + // test after query rewrite, outfile still work + String sql = "select * from test.outfile1 where `date` between '2021-10-07' and '2021-10-11'" + + "INTO OUTFILE \"file:///tmp/1_\" FORMAT AS CSV PROPERTIES ( \"column_separator\" = \",\", \"line_delimiter\" = \"\\n\", \"max_file_size\" = \"500MB\" );"; + String explainStr = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql); + Assert.assertTrue(explainStr.contains("PREDICATES: `date` >= '2021-10-07 00:00:00', `date` <= '2021-10-11 00:00:00'")); + } + } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
