SbloodyS commented on code in PR #18020:
URL:
https://github.com/apache/dolphinscheduler/pull/18020#discussion_r2887809215
##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/parameters/SqlParameters.java:
##########
@@ -58,6 +58,18 @@ public class SqlParameters extends AbstractParameters {
*/
private String sql;
+ /**
+ * sql source
+ * SCRIPT: inline sql text
+ * FILE: sql from resource center file
+ */
+ private String sqlSource;
Review Comment:
Using enum here.
##########
dolphinscheduler-ui/src/views/projects/task/components/node/fields/use-sql.ts:
##########
@@ -47,6 +67,22 @@ export function useSql(model: { [field: string]: any }):
IJsonItem[] {
language: 'sql'
}
},
+ {
+ type: 'tree-select',
+ field: 'sqlResource',
+ name: t('project.node.sql_resource_file'),
+ span: 24,
+ if: () => model.sqlSource === 'FILE',
+ props: {
+ placeholder: t('project.node.resources_tips'),
+ keyField: 'fullName',
+ labelField: 'name',
+ disabledField: 'disable'
+ },
+ slots: {
+ // 这里占位,真正的资源数据从全局资源 store 中获取,保持与 use-resources 一致行为
Review Comment:
```suggestion
```
##########
dolphinscheduler-task-plugin/dolphinscheduler-task-sql/src/test/java/org/apache/dolphinscheduler/plugin/task/sql/SqlTaskTest.java:
##########
@@ -17,6 +17,75 @@
package org.apache.dolphinscheduler.plugin.task.sql;
+import org.apache.dolphinscheduler.common.utils.JSONUtils;
+import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
+import org.apache.dolphinscheduler.plugin.task.api.parameters.SqlParameters;
+import org.apache.dolphinscheduler.plugin.task.api.resource.ResourceContext;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.lang.reflect.Method;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+class SqlTaskTest {
+
+ @Test
+ void testSqlLoadedFromResourceFileWhenSqlIsEmpty(@TempDir Path tempDir)
throws Exception {
+ Path sqlFile = tempDir.resolve("test.sql");
+ String sqlContent = "SELECT 1";
+ Files.write(sqlFile, sqlContent.getBytes(StandardCharsets.UTF_8));
+
+ SqlParameters sqlParameters = new SqlParameters();
+ sqlParameters.setType("MYSQL");
+ sqlParameters.setDatasource(1);
+ sqlParameters.setSql(null);
+ sqlParameters.setSqlResource("/sql/test.sql");
+
+ TaskExecutionContext taskExecutionContext = new TaskExecutionContext();
+
taskExecutionContext.setTaskParams(JSONUtils.toJsonString(sqlParameters));
+ taskExecutionContext.setScheduleTime(System.currentTimeMillis());
+
+ ResourceContext resourceContext = new ResourceContext();
+ resourceContext.addResourceItem(ResourceContext.ResourceItem.builder()
+ .resourceAbsolutePathInStorage(sqlParameters.getSqlResource())
+ .resourceAbsolutePathInLocal(sqlFile.toString())
+ .build());
+ taskExecutionContext.setResourceContext(resourceContext);
+
+ SqlTask sqlTask = new SqlTask(taskExecutionContext);
+
+ Method ensureSqlContent =
SqlTask.class.getDeclaredMethod("ensureSqlContent");
+ ensureSqlContent.setAccessible(true);
+ ensureSqlContent.invoke(sqlTask);
+
+ SqlParameters loadedParameters = (SqlParameters)
sqlTask.getParameters();
+ Assertions.assertEquals(sqlContent, loadedParameters.getSql());
+ }
+}
+
+/*
+ * 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.dolphinscheduler.plugin.task.sql;
Review Comment:
Why adding this?
--
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]