morrySnow commented on code in PR #21197:
URL: https://github.com/apache/doris/pull/21197#discussion_r1254384520
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -1427,6 +1429,24 @@ private LogicalPlan withExplain(LogicalPlan inputPlan,
ExplainContext ctx) {
});
}
+ private LogicalPlan withOutFile(LogicalPlan plan, OutFileClauseContext
ctx) {
+ if (ctx == null) {
+ return plan;
+ }
+ String format = "csv";
+ if (ctx.format != null) {
+ format = ctx.format.getText();
+ }
+ Map<String, String> properties = Maps.newHashMap();
+ for (TvfPropertyContext argument : ctx.properties) {
+ String key = parseTVFPropertyItem(argument.key);
Review Comment:
if reuse `parseTVFPropertyItem`, please rename it to a property name
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalFileSink.java:
##########
@@ -0,0 +1,119 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.trees.plans.logical;
+
+import org.apache.doris.nereids.memo.GroupExpression;
+import org.apache.doris.nereids.properties.LogicalProperties;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.plans.Plan;
+import org.apache.doris.nereids.trees.plans.PlanType;
+import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+
+/**
+ * logicalFileSink for select into outfile
+ */
+public class LogicalFileSink<CHILD_TYPE extends Plan> extends
LogicalUnary<CHILD_TYPE> {
+ private final String filePath;
+ private final String format;
+ private final Map<String, String> properties;
+
+ public LogicalFileSink(String filePath, String format, Map<String, String>
properties, CHILD_TYPE child) {
+ this(filePath, format, properties, Optional.empty(), Optional.empty(),
child);
+ }
+
+ public LogicalFileSink(String filePath, String format, Map<String, String>
properties,
+ Optional<GroupExpression> groupExpression,
Optional<LogicalProperties> logicalProperties,
+ CHILD_TYPE child) {
+ super(PlanType.LOGICAL_FILE_SINK, groupExpression, logicalProperties,
child);
+ this.filePath = filePath;
+ this.format = format;
+ this.properties = properties;
Review Comment:
ImmutableMap.copyOf(Objects.requireNonNull(properties))
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PlanTranslatorContext.java:
##########
@@ -218,4 +221,12 @@ public TupleDescriptor getTupleDesc(TupleId tupleId) {
public DescriptorTable getDescTable() {
return descTable;
}
+
+ public void setOutFileClause(OutFileClause outFileClause) {
+ this.outFileClause = outFileClause;
+ }
+
+ public OutFileClause getOutFileClause() {
+ return outFileClause;
+ }
Review Comment:
where to use this?
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalFileSink.java:
##########
@@ -0,0 +1,119 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.trees.plans.logical;
+
+import org.apache.doris.nereids.memo.GroupExpression;
+import org.apache.doris.nereids.properties.LogicalProperties;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.plans.Plan;
+import org.apache.doris.nereids.trees.plans.PlanType;
+import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+
+/**
+ * logicalFileSink for select into outfile
+ */
+public class LogicalFileSink<CHILD_TYPE extends Plan> extends
LogicalUnary<CHILD_TYPE> {
+ private final String filePath;
+ private final String format;
+ private final Map<String, String> properties;
+
+ public LogicalFileSink(String filePath, String format, Map<String, String>
properties, CHILD_TYPE child) {
+ this(filePath, format, properties, Optional.empty(), Optional.empty(),
child);
+ }
+
+ public LogicalFileSink(String filePath, String format, Map<String, String>
properties,
+ Optional<GroupExpression> groupExpression,
Optional<LogicalProperties> logicalProperties,
+ CHILD_TYPE child) {
+ super(PlanType.LOGICAL_FILE_SINK, groupExpression, logicalProperties,
child);
+ this.filePath = filePath;
+ this.format = format;
Review Comment:
requireNonNull
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java:
##########
@@ -315,7 +318,36 @@ public PlanFragment
visitPhysicalOlapTableSink(PhysicalOlapTableSink<? extends P
);
rootFragment.setSink(sink);
+
rootFragment.setOutputPartition(DataPartition.UNPARTITIONED);
+
+ return rootFragment;
+ }
+
+ @Override
+ public PlanFragment visitPhysicalFileSink(PhysicalFileSink<? extends Plan>
fileSink,
+ PlanTranslatorContext context) {
+ PlanFragment rootFragment = fileSink.child().accept(this, context);
+ OutFileClause outFile = new OutFileClause(
+ fileSink.getFilePath(),
+ fileSink.getFormat(),
+ fileSink.getProperties()
+ );
+
+ List<Expr> outputExprs = Lists.newArrayList();
+ fileSink.getOutput().stream().map(Slot::getExprId)
+ .forEach(exprId ->
outputExprs.add(context.findSlotRef(exprId)));
+ rootFragment.setOutputExprs(outputExprs);
+
+ try {
+ outFile.analyze(null, outputExprs,
+
fileSink.getOutput().stream().map(NamedExpression::getName).collect(Collectors.toList()));
Review Comment:
why need reuse legacy planner's analyze?
--
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]