diff --git a/linkis-web/src/apps/PythonModule/public/tutorial.html b/linkis-web/src/apps/PythonModule/public/tutorial.html new file mode 100644 index 0000000000..794b2bc0ed --- /dev/null +++ b/linkis-web/src/apps/PythonModule/public/tutorial.html @@ -0,0 +1,87 @@ + + +
+ + +a. 对于py 文件你的模块名一定要和文件名一致,如hello_world.py 模块名就是hello_world,您可以在里面定义你的python方法和class等,如下:
+
+ #文件名一定是 hello_world.py
+def add_hello_world(name):
+ return "hello world {}".format(name)
+
+
+ b. 对于zip文件需要稍微复杂点,你得遵循Python模块包的文件格式,如下:
+
+ #zip文件名hello_world.zip
+hello_world.zip
+├── hello_world # 包目录,必须为模块名
+├── __init__.py # 必须有该文件
+├── hello_world.py # 其它python文件
+#hello_world.py文件内容如下:
+def add_hello_world(name):
+ return "hello world {}".format(name)
+
+
+ 需要有 __init__.py
文件才能让 Python 将包含该文件的目录当作包来处理,可以只是一个空文件。你也可以直接去pip网站上面下载对应的包,然后通过zip压缩即可
第一步点击新增
+第二步选择对应的引擎,分别对于Spark(.py脚本),python(.python脚本),通用(.py脚本和.python脚本)
+第三步上传之前准备的模块物料,如果要更新模块内容需要先将旧的模块删除后再重新上传
+第四步选择加载才可以进行使用
+第五步如果你的模块不需要了,可以选择过期,等同于删除
+ +1. 如果你的模块已经加好了,可以直接在脚本中通过import进行使用如下:
+
+ from hello_world import add_hello_world
+add_hello_world("peace")
+
+
+ 2. 可以将对应的模块注册成Spark的UDF进行使用
+
+ from pyspark.sql.functions import udf
+from pyspark.sql.types import StringType
+from hello_world import add_hello_world
+add_hello_world_udf = udf(add_hello_world, StringType())
+df=spark.sql("select * from dws_demo.demo_user_info limit 100")
+df_transformed = df.withColumn("username", add_hello_world_udf(df["username"]))
+df_transformed.show()
+
+
+ a. 对于py 文件你的模块名一定要和文件名一致,如hello_world.py 模块名就是hello_world,您可以在里面定义你的python方法和class等,如下:
#文件名一定是 hello_world.py
@@ -823,28 +847,42 @@ df_transformed.show()
: 'Python';
},
},
- {
- prop: 'status',
- label: $t('status'),
- formatter: ({
- row,
- column,
- rowIndex,
- coloumIndex,
- cellValue,
- }) => {
- return row.isExpire === 0
- ? $t('normal')
- : $t('expire');
- },
- },
+ // {
+ // prop: 'status',
+ // label: $t('status'),
+ // formatter: ({
+ // row,
+ // column,
+ // rowIndex,
+ // coloumIndex,
+ // cellValue,
+ // }) => {
+ // return row.isExpire === 0
+ // ? $t('normal')
+ // : $t('expire');
+ // },
+ // },
{
prop: 'path',
label: $t('pathInfo'),
},
+ {
+ prop: 'pythonModule',
+ label: $t('pythonModule'),
+ formatter: ({row, column ,rowIndex, columnIndex, cellValue}) => {
+ if(!row.pythonModule) {
+ return '- -'
+ }
+ }
+ },
{
prop: 'description',
label: $t('moduleDescription'),
+ formatter: ({row, column, rowIndex, columnIndex, cellValue}) => {
+ if(!row.description) {
+ return '- -'
+ }
+ }
},
{
prop: 'createTime',
diff --git a/linkis-web/src/apps/PythonModule/src/pages/index/main.js b/linkis-web/src/apps/PythonModule/src/pages/index/main.js
index 14a8942948..c829101d01 100644
--- a/linkis-web/src/apps/PythonModule/src/pages/index/main.js
+++ b/linkis-web/src/apps/PythonModule/src/pages/index/main.js
@@ -6,7 +6,7 @@ export class Main extends LetgoPageBase {
this.pythonModuleName = '';
this.userName = '';
this.engineType = '';
- this.isExpired = 0;
+ // this.isExpired = 0;
this.isLoaded = null;
this.currentPage = 1;
this.pageSize = 10;
@@ -17,9 +17,10 @@ export class Main extends LetgoPageBase {
this.newModuleName = '';
this.selectedEngineType = 'spark';
this.selectedModuleDescription = '';
+ this.selectedModulePythonModule = '';
this.selectedModulePath = '';
this.selectedModuleIsLoad = 1;
- this.selectedModuleIsExpire = 0;
+ // this.selectedModuleIsExpire = 0;
this.selectedModuleId = null;
this.selectedModuleFile = null;
this.selectedModuleFileError = '';
@@ -33,6 +34,8 @@ export class Main extends LetgoPageBase {
this.addFormRef = null;
this.editFormRef = null;
this.tutorialVisible = false;
+ this.isUploading = false;
+ this.getDep = false;
}
onMounted () {
@@ -49,7 +52,7 @@ export class Main extends LetgoPageBase {
engineType: this.engineType,
username: this.userName,
// isLoad: this.isLoaded,
- isExpire: this.isExpired,
+ isExpire: 0,
pageNow: this.currentPage,
pageSize: this.pageSize
};
@@ -58,7 +61,7 @@ export class Main extends LetgoPageBase {
}
const response =
await this.$pageCode.apiPythonlistUdf.trigger(params);
- this.pythonModuleList = response.data.pythonList;
+ this.pythonModuleList = response.data.pythonList
this.totalRecords = response.data.totalPage;
return response;
} catch (error) {
@@ -76,7 +79,7 @@ export class Main extends LetgoPageBase {
this.pythonModuleName = '';
this.userName = '';
this.engineType = '';
- this.isExpired = 0;
+ // this.isExpired = 0;
this.isLoaded = null;
this.currentPage = 1;
this.pageSize = 10;
@@ -87,11 +90,12 @@ export class Main extends LetgoPageBase {
this.addPythonModuleVisible = true;
this.selectedModule.name = '';
this.selectedModule.engineType = 'spark';
- this.selectedModule.isExpire = 0;
+ // this.selectedModule.isExpire = 0;
this.selectedModule.isLoad = 1;
this.selectedModule.path = '';
this.selectedModule.fileList = [];
this.selectedModule.description = '';
+ this.selectedModule.pythonModule = '';
}
showTutorial () {
@@ -169,7 +173,7 @@ export class Main extends LetgoPageBase {
throw new Error(this.$pageCode.$t('moduleNameTooLong'));
}
// 名称只支持数字字母下划线,且以字母开头
- if (!/^[a-zA-Z][a-zA-Z0-9_]*$/.test(newModuleName.split('.')[0])) {
+ if (!/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(newModuleName.split('.')[0])) {
this.$utils.FMessage.error(this.$pageCode.$t('moduleNameNotFormat'));
throw new Error(this.$pageCode.$t('moduleNameNotFormat'));
}
@@ -209,18 +213,32 @@ export class Main extends LetgoPageBase {
}
}
+ cutExtension(fileName) {
+ const pyIndex = fileName.indexOf('.py');
+ const zipIndex = fileName.indexOf('.zip');
+ const targzIndex = fileName.indexOf('.tar.gz');
+ if(Math.max(pyIndex, zipIndex, targzIndex) !== -1) {
+ return fileName.substring(0, Math.max(pyIndex, zipIndex, targzIndex));
+ } else {
+ return fileName;
+ }
+ }
async handleUploadHttpRequest (options) {
try {
+ this.isUploading = true;
const formData = new FormData();
- window.console.log('options:', options);
formData.append('file', options.file);
formData.append('fileName', options.file.name);
const response = await this.$pageCode.apiPythonuploadFilesystem.trigger(formData);
this.selectedModule.path = response.data.filePath;
- this.selectedModule.name = options.file.name.split('.')[0];
+ this.selectedModule.name = this.cutExtension(response.data.fileName);
+ this.selectedModule.pythonModule = response.data.dependencies;
+ this.getDep = true;
this.selectedModule.fileList = [options.file];
+ this.isUploading = false;
} catch (err) {
window.console.error(err);
+ this.isUploading = false;
// this.$utils.FMessage.error('上传失败');
}
}
@@ -231,8 +249,9 @@ export class Main extends LetgoPageBase {
selectedModuleDescription,
selectedModulePath,
selectedModuleIsLoad,
- selectedModuleIsExpire,
- selectedModuleId
+ // selectedModuleIsExpire,
+ selectedModulePythonModule,
+ selectedModuleId,
) {
const params = {
name: newModuleName,
@@ -240,7 +259,8 @@ export class Main extends LetgoPageBase {
path: selectedModulePath,
engineType: selectedEngineType,
isLoad: selectedModuleIsLoad,
- isExpire: selectedModuleIsExpire
+ pythonModule: selectedModulePythonModule,
+ isExpire: 0
};
if (selectedModuleId) {
params.id = selectedModuleId;
@@ -284,7 +304,9 @@ export class Main extends LetgoPageBase {
this.selectedModule.description,
this.selectedModule.path,
this.selectedModule.isLoad,
- this.selectedModule.isExpire
+ this.selectedModule.pythonModule,
+
+ // this.selectedModule.isExpire
);
this.addPythonModuleVisible = false;
this.loadPythonModuleList();
@@ -302,8 +324,9 @@ export class Main extends LetgoPageBase {
this.selectedModule.description,
this.selectedModule.path,
this.selectedModule.isLoad,
- this.selectedModule.isExpire,
- this.selectedModule.id
+ // this.selectedModule.isExpire,
+ this.selectedModule.pythonModule,
+ this.selectedModule.id,
);
this.closeEditModuleModal();
this.loadPythonModuleList();
@@ -338,16 +361,19 @@ export class Main extends LetgoPageBase {
}
async handleLoadStatusChange () {
- const { id, name, path, isExpire, isLoad, engineType, description } =
+ const { id, name, path,
+ // isExpire,
+ isLoad, engineType, description, pythonModule } =
this.selectedModule;
window.console.log({
id,
name,
path,
- isExpire,
+ // isExpire,
isLoad,
engineType,
- description
+ description,
+ pythonModule
});
const targetLoadStatus = isLoad === 1 ? 0 : 1;
if (id === null) {
@@ -363,8 +389,9 @@ export class Main extends LetgoPageBase {
description,
path,
targetLoadStatus,
- isExpire,
- id
+ // isExpire,
+ pythonModule,
+ id,
);
await this.loadPythonModuleList();
} catch (error) {
@@ -377,6 +404,7 @@ export class Main extends LetgoPageBase {
closeAddModuleModal () {
this.addPythonModuleVisible = false;
+ this.getDep = false;
}
handleFileListChange ({ file, fileList }) {
@@ -385,6 +413,7 @@ export class Main extends LetgoPageBase {
closeEditModuleModal () {
this.editPythonModuleVisible = false;
+ this.getDep = false;
}
closeDeleteConfirmation () {
@@ -394,4 +423,9 @@ export class Main extends LetgoPageBase {
closeLoadStatusChangeConfirmation () {
this.loadStatusChangeConfirmationVisible = false;
}
+
+ openNewTab() {
+ window.open('./tutorial.html', '_blank');
+ this.tutorialVisible = false;
+ }
}
diff --git a/linkis-web/src/apps/linkis/module/datasource/datasourceForm/index.vue b/linkis-web/src/apps/linkis/module/datasource/datasourceForm/index.vue
index c19af012d3..14f749c6ab 100644
--- a/linkis-web/src/apps/linkis/module/datasource/datasourceForm/index.vue
+++ b/linkis-web/src/apps/linkis/module/datasource/datasourceForm/index.vue
@@ -22,6 +22,7 @@
v-model="fApi"
:option="options"
:value.sync="formData"
+ @change="handleFormChange"
/>