morningman commented on code in PR #15511:
URL: https://github.com/apache/doris/pull/15511#discussion_r1084074726


##########
fe/fe-core/src/main/cup/sql_parser.cup:
##########
@@ -618,9 +618,13 @@ terminal String
     KW_MTMV,
     KW_TYPECAST,
     KW_HISTOGRAM,
+<<<<<<< HEAD

Review Comment:
   conflict



##########
fe/fe-core/src/main/java/org/apache/doris/load/loadv2/LoadManager.java:
##########
@@ -151,6 +181,183 @@ public void createLoadJobV1FromMultiStart(String 
fullDbName, String label) throw
         }
     }
 
+    public LoadJobRowResult executeMySqlLoadJobFromStmt(ConnectContext 
context, LoadStmt stmt)
+            throws IOException, LoadException {
+        LoadJobRowResult loadResult = new LoadJobRowResult();

Review Comment:
   How about moving these methods to a separate class to make LoadManager 
simple?



##########
fe/fe-common/src/main/java/org/apache/doris/common/io/ByteBufferNetworkInputStream.java:
##########
@@ -0,0 +1,105 @@
+// 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.common.io;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+public class ByteBufferNetworkInputStream extends InputStream {
+    private ArrayBlockingQueue<ByteArrayInputStream> queue;
+    private ByteArrayInputStream currentInputStream;
+    private volatile boolean finished = false;
+    private volatile boolean closed = false;
+
+    public ByteBufferNetworkInputStream() {
+        this(32);
+    }
+
+    public ByteBufferNetworkInputStream(int capacity) {
+        this.queue = new ArrayBlockingQueue<>(capacity);
+    }
+
+    public void fillByteBuffer(ByteBuffer buffer) throws IOException, 
InterruptedException {
+        if (closed) {
+            throw new IOException("Stream is already closed.");
+        }
+        ByteArrayInputStream inputStream = new 
ByteArrayInputStream(buffer.array(), buffer.position(), buffer.limit());
+        queue.offer(inputStream, 300, TimeUnit.SECONDS);

Review Comment:
   Is there any reason to set timeout to 300s?



##########
fe/fe-core/src/main/java/org/apache/doris/load/loadv2/LoadManager.java:
##########
@@ -151,6 +181,183 @@ public void createLoadJobV1FromMultiStart(String 
fullDbName, String label) throw
         }
     }
 
+    public LoadJobRowResult executeMySqlLoadJobFromStmt(ConnectContext 
context, LoadStmt stmt)
+            throws IOException, LoadException {
+        LoadJobRowResult loadResult = new LoadJobRowResult();
+        // Mysql data load only have one data desc
+        DataDescription dataDesc = stmt.getDataDescriptions().get(0);
+        String database = dataDesc.getDbName();
+        String table = dataDesc.getTableName();
+        List<String> filePaths = dataDesc.getFilePaths();
+        try (final CloseableHttpClient httpclient = 
HttpClients.createDefault()) {
+            for (String file : filePaths) {
+                InputStreamEntity entity = getInputStreamEntity(context, 
dataDesc.isClientLocal(), file);
+                HttpPut request = generateRequestForMySqlLoad(entity, 
dataDesc, database, table);
+                try (final CloseableHttpResponse response = 
httpclient.execute(request)) {
+                    JSONObject result = 
JSON.parseObject(EntityUtils.toString(response.getEntity()));
+                    if 
(!result.getString("Status").equalsIgnoreCase("Success")) {
+                        LOG.warn("Execute stream load for mysql data load 
failed with message: " + request);
+                        throw new LoadException(result.getString("Message"));
+                    }
+                    loadResult.incRecords(result.getLong("NumberLoadedRows"));
+                    
loadResult.incSkipped(result.getIntValue("NumberFilteredRows"));
+                }
+            }
+        }
+        return loadResult;
+    }
+
+    private InputStreamEntity getInputStreamEntity(ConnectContext context, 
boolean isClintLocal, String file)
+            throws IOException {
+        InputStream inputStream;
+        if (isClintLocal) {

Review Comment:
   ```suggestion
           if (isClientLocal) {
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java:
##########
@@ -1836,6 +1841,41 @@ private void handleExplainStmt(String result) throws 
IOException {
         context.getState().setEof();
     }
 
+    private void handleLoadStmt() {
+        try {
+            LoadStmt loadStmt = (LoadStmt) parsedStmt;
+            EtlJobType jobType = loadStmt.getEtlJobType();
+            if (jobType == EtlJobType.UNKNOWN) {
+                throw new DdlException("Unknown load job type");
+            }
+            if (jobType == EtlJobType.HADOOP) {
+                throw new DdlException("Load job by hadoop cluster is 
disabled."
+                        + " Try using broker load. See 'help broker load;'");
+            }
+            LoadManager loadManager = context.getEnv().getLoadManager();
+            if (jobType == EtlJobType.LOCAL_FILE) {
+                if (!context.getCapability().isClientLocalFile()) {
+                    throw new DdlException("Doris server does not support load 
local file from mysql client.");

Review Comment:
   The error msg is confusing.
   The `if` says `not a client local file`, but err msg says "not support local 
file from client"?



##########
fe/fe-core/src/main/jflex/sql_scanner.flex:
##########
@@ -479,9 +479,13 @@ import org.apache.doris.qe.SqlModeHelper;
         keywordMap.put("year", new Integer(SqlParserSymbols.KW_YEAR));
         keywordMap.put("mtmv", new Integer(SqlParserSymbols.KW_MTMV));
         keywordMap.put("histogram", new 
Integer(SqlParserSymbols.KW_HISTOGRAM));
+<<<<<<< HEAD
         keywordMap.put("auto", new Integer(SqlParserSymbols.KW_AUTO));
         keywordMap.put("prepare", new Integer(SqlParserSymbols.KW_PREPARE));
         keywordMap.put("execute", new Integer(SqlParserSymbols.KW_EXECUTE));
+=======

Review Comment:
   Conflict



-- 
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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to