zwangsheng commented on code in PR #5616:
URL: https://github.com/apache/kyuubi/pull/5616#discussion_r1381261426


##########
kyuubi-server/web-ui/src/views/editor/components/Editor.vue:
##########
@@ -0,0 +1,261 @@
+<!--
+* 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.
+-->
+
+<template>
+  <div class="editor">
+    <el-space>
+      <el-select v-model="param.engineType" :placeholder="$t('engine_type')">

Review Comment:
   We only support Spark SQL Engine now, so maybe we should disable this 
el-select.



##########
kyuubi-server/web-ui/src/api/editor/index.ts:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.
+ */
+
+import request from '@/utils/request'
+
+export function openSession(data: any): any {

Review Comment:
   Need to follow TypeScript strict mode and avoid heavy use of `any`. 
   
   We know these params, can we wrap a class to use?
   



##########
kyuubi-server/web-ui/src/api/server/index.ts:
##########
@@ -17,7 +17,7 @@
 
 import request from '@/utils/request'
 
-export function getAllServer() {
+export function getAllServer(): any {

Review Comment:
   Return `Array<IServer>`?



##########
kyuubi-server/web-ui/src/router/index.ts:
##########
@@ -20,7 +20,7 @@ import overviewRoutes from './overview'
 import managementRoutes from './management'
 import detailRoutes from './detail'
 import swaggerRoutes from './swagger'
-import labRoutes from './lab'
+import labRoutes from './editor'

Review Comment:
   labRoutes => editorRoutes



##########
kyuubi-server/web-ui/src/locales/en_US/index.ts:
##########
@@ -37,21 +37,25 @@ export default {
   engine_ui: 'Engine UI',
   failure_reason: 'Failure Reason',
   session_properties: 'Session Properties',
+  no_data: 'No data yet',

Review Comment:
   Please correct me if this is incorrect, we return no_data when query success 
but without empty data, so this should be 'No data'?



##########
kyuubi-server/web-ui/src/views/editor/components/Editor.vue:
##########
@@ -0,0 +1,261 @@
+<!--
+* 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.
+-->
+
+<template>
+  <div class="editor">
+    <el-space>
+      <el-select v-model="param.engineType" :placeholder="$t('engine_type')">
+        <el-option
+          v-for="item in getEngineType()"
+          :key="item"
+          :label="item"
+          :value="item" />
+      </el-select>
+      <el-button
+        :disabled="!param.engineType || !editorVariables.content"
+        :loading="resultLoading"
+        type="primary"
+        icon="VideoPlay"
+        @click="handleQuerySql">
+        {{ $t('operation.run') }}
+      </el-button>
+      <el-dropdown @command="handleChangeLimit">
+        <span class="el-dropdown-link">
+          Limit: {{ limit }}
+          <el-icon class="el-icon--right">
+            <arrow-down />
+          </el-icon>
+        </span>
+        <template #dropdown>
+          <el-dropdown-menu>
+            <el-dropdown-item v-for="l in limits" :key="l" :command="l">
+              Limit: {{ l }}
+            </el-dropdown-item>
+          </el-dropdown-menu>
+        </template>
+      </el-dropdown>
+    </el-space>
+    <section>
+      <MonacoEditor
+        v-model="editorVariables.content"
+        :language="editorVariables.language"
+        :theme="theme"
+        @editor-mounted="editorMounted"
+        @change="handleContentChange"
+        @editor-save="editorSave" />
+    </section>
+    <pre v-show="sqlLog" v-loading="logLoading">{{ sqlLog }}</pre>
+    <el-tabs v-model="activeTab" type="card" class="result-el-tabs">
+      <el-tab-pane
+        v-loading="resultLoading"
+        :label="`Result${sqlResult?.length ? ` (${sqlResult?.length})` : ''}`"
+        name="result">
+        <Result :data="sqlResult" />
+      </el-tab-pane>
+    </el-tabs>
+  </div>
+</template>
+
+<script lang="ts" setup>
+  import MonacoEditor from '@/components/monaco-editor/index.vue'
+  import Result from './Result.vue'
+  import { ref, reactive, onUnmounted, toRaw } from 'vue'
+  import type { Ref } from 'vue'
+  import * as monaco from 'monaco-editor'
+  import { format } from 'sql-formatter'
+  import { ElMessage } from 'element-plus'
+  import { useI18n } from 'vue-i18n'
+  import { getEngineType } from '@/utils/engine'
+  import {
+    openSession,
+    closeSession,
+    runSql,
+    getSqlRowset,
+    getSqlMetadata,
+    log
+  } from '@/api/editor'
+  import type { IResponse, ISqlResult, IFields, ILog } from './types'
+
+  const { t } = useI18n()
+  const param = reactive({
+    engineType: 'SPARK_SQL'
+  })
+  const limit = ref(10)
+  const limits = ref([10, 50, 100])
+  const sqlResult: Ref<any[] | null> = ref(null)
+  const sqlLog = ref('')
+  const activeTab = ref('result')
+  const resultLoading = ref(false)
+  const logLoading = ref(false)
+  const sessionIdentifier = ref('')
+  const theme = ref('customTheme')
+  const editorVariables = reactive({
+    editor: {} as any,
+    language: 'sql',
+    content: '',
+    options: {}
+  })
+
+  const editorMounted = (editor: monaco.editor.IStandaloneCodeEditor) => {
+    editorVariables.editor = editor
+  }
+  const handleFormat = () => {
+    toRaw(editorVariables.editor).setValue(
+      format(toRaw(editorVariables.editor).getValue())
+    )
+  }
+
+  const editorSave = () => {
+    handleFormat()
+  }
+
+  const handleContentChange = (value: string) => {
+    editorVariables.content = value
+  }
+
+  const handleQuerySql = async () => {
+    resultLoading.value = true
+    logLoading.value = true
+    const openSessionResponse: IResponse = await openSession({
+      'kyuubi.engine.type': param.engineType
+    }).catch(errorCatch)
+    if (!openSessionResponse) return
+    sessionIdentifier.value = openSessionResponse.identifier
+
+    const runSqlResponse: IResponse = await runSql(
+      {
+        statement: editorVariables.content,
+        runAsync: false
+      },
+      sessionIdentifier.value
+    ).catch(errorCatch)
+    if (!runSqlResponse) return
+
+    Promise.all([
+      getSqlRowset({
+        operationHandleStr: runSqlResponse.identifier,
+        fetchorientation: 'FETCH_NEXT',
+        maxrows: limit.value
+      }),
+      getSqlMetadata({
+        operationHandleStr: runSqlResponse.identifier
+      })
+    ])
+      .then((result: any[]) => {
+        sqlResult.value = result[0]?.rows?.map((row: IFields) => {
+          const map: { [key: string]: any } = {}
+          row.fields?.forEach(({ value }: ISqlResult, index: number) => {
+            map[result[1].columns[index]?.columnName] = value
+          })
+          return map
+        })
+      })
+      .catch(() => {
+        sqlResult.value = []

Review Comment:
   Should catch error



##########
kyuubi-server/web-ui/src/views/editor/components/Editor.vue:
##########
@@ -0,0 +1,261 @@
+<!--
+* 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.
+-->
+
+<template>
+  <div class="editor">
+    <el-space>
+      <el-select v-model="param.engineType" :placeholder="$t('engine_type')">
+        <el-option
+          v-for="item in getEngineType()"
+          :key="item"
+          :label="item"
+          :value="item" />
+      </el-select>
+      <el-button
+        :disabled="!param.engineType || !editorVariables.content"
+        :loading="resultLoading"
+        type="primary"
+        icon="VideoPlay"
+        @click="handleQuerySql">
+        {{ $t('operation.run') }}
+      </el-button>
+      <el-dropdown @command="handleChangeLimit">
+        <span class="el-dropdown-link">
+          Limit: {{ limit }}
+          <el-icon class="el-icon--right">
+            <arrow-down />
+          </el-icon>
+        </span>
+        <template #dropdown>
+          <el-dropdown-menu>
+            <el-dropdown-item v-for="l in limits" :key="l" :command="l">
+              Limit: {{ l }}
+            </el-dropdown-item>
+          </el-dropdown-menu>
+        </template>
+      </el-dropdown>
+    </el-space>
+    <section>
+      <MonacoEditor
+        v-model="editorVariables.content"
+        :language="editorVariables.language"
+        :theme="theme"
+        @editor-mounted="editorMounted"
+        @change="handleContentChange"
+        @editor-save="editorSave" />
+    </section>
+    <pre v-show="sqlLog" v-loading="logLoading">{{ sqlLog }}</pre>
+    <el-tabs v-model="activeTab" type="card" class="result-el-tabs">
+      <el-tab-pane
+        v-loading="resultLoading"
+        :label="`Result${sqlResult?.length ? ` (${sqlResult?.length})` : ''}`"
+        name="result">
+        <Result :data="sqlResult" />
+      </el-tab-pane>
+    </el-tabs>
+  </div>
+</template>
+
+<script lang="ts" setup>
+  import MonacoEditor from '@/components/monaco-editor/index.vue'
+  import Result from './Result.vue'
+  import { ref, reactive, onUnmounted, toRaw } from 'vue'
+  import type { Ref } from 'vue'
+  import * as monaco from 'monaco-editor'
+  import { format } from 'sql-formatter'
+  import { ElMessage } from 'element-plus'
+  import { useI18n } from 'vue-i18n'
+  import { getEngineType } from '@/utils/engine'
+  import {
+    openSession,
+    closeSession,
+    runSql,
+    getSqlRowset,
+    getSqlMetadata,
+    log
+  } from '@/api/editor'
+  import type { IResponse, ISqlResult, IFields, ILog } from './types'
+
+  const { t } = useI18n()
+  const param = reactive({
+    engineType: 'SPARK_SQL'
+  })
+  const limit = ref(10)
+  const limits = ref([10, 50, 100])
+  const sqlResult: Ref<any[] | null> = ref(null)
+  const sqlLog = ref('')
+  const activeTab = ref('result')
+  const resultLoading = ref(false)
+  const logLoading = ref(false)
+  const sessionIdentifier = ref('')
+  const theme = ref('customTheme')
+  const editorVariables = reactive({
+    editor: {} as any,
+    language: 'sql',
+    content: '',
+    options: {}
+  })
+
+  const editorMounted = (editor: monaco.editor.IStandaloneCodeEditor) => {
+    editorVariables.editor = editor
+  }
+  const handleFormat = () => {
+    toRaw(editorVariables.editor).setValue(
+      format(toRaw(editorVariables.editor).getValue())
+    )
+  }
+
+  const editorSave = () => {
+    handleFormat()
+  }
+
+  const handleContentChange = (value: string) => {
+    editorVariables.content = value
+  }
+
+  const handleQuerySql = async () => {
+    resultLoading.value = true
+    logLoading.value = true
+    const openSessionResponse: IResponse = await openSession({
+      'kyuubi.engine.type': param.engineType
+    }).catch(errorCatch)
+    if (!openSessionResponse) return
+    sessionIdentifier.value = openSessionResponse.identifier
+
+    const runSqlResponse: IResponse = await runSql(
+      {
+        statement: editorVariables.content,
+        runAsync: false
+      },
+      sessionIdentifier.value
+    ).catch(errorCatch)
+    if (!runSqlResponse) return
+
+    Promise.all([
+      getSqlRowset({
+        operationHandleStr: runSqlResponse.identifier,
+        fetchorientation: 'FETCH_NEXT',
+        maxrows: limit.value
+      }),
+      getSqlMetadata({
+        operationHandleStr: runSqlResponse.identifier
+      })
+    ])
+      .then((result: any[]) => {
+        sqlResult.value = result[0]?.rows?.map((row: IFields) => {
+          const map: { [key: string]: any } = {}
+          row.fields?.forEach(({ value }: ISqlResult, index: number) => {
+            map[result[1].columns[index]?.columnName] = value
+          })
+          return map
+        })
+      })
+      .catch(() => {
+        sqlResult.value = []
+      })
+      .finally(() => {
+        resultLoading.value = false
+      })
+
+    sqlLog.value = await log(runSqlResponse.identifier)
+      .then((res: ILog) => {
+        return res?.logRowSet?.join('\r\n')
+      })
+      .catch(() => '')

Review Comment:
   Should catch error



##########
kyuubi-server/web-ui/src/components/monaco-editor/type.ts:
##########
@@ -53,10 +53,10 @@ export const editorProps = {
     default: 'sql'
   },
   theme: {
-    type: String as PropType<Theme>,
-    validator(value: string): boolean {
-      return ['vs', 'vs-dark'].includes(value)
-    },
+    type: String as PropType<any>,
+    // validator(value: string): boolean {
+    //   return ['vs', 'vs-dark'].includes(value)
+    // },

Review Comment:
   This comment doesn't seem to make sense, maybe we can remove it?



##########
kyuubi-server/web-ui/src/views/editor/components/Editor.vue:
##########
@@ -0,0 +1,261 @@
+<!--
+* 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.
+-->
+
+<template>
+  <div class="editor">
+    <el-space>
+      <el-select v-model="param.engineType" :placeholder="$t('engine_type')">
+        <el-option
+          v-for="item in getEngineType()"
+          :key="item"
+          :label="item"
+          :value="item" />
+      </el-select>
+      <el-button
+        :disabled="!param.engineType || !editorVariables.content"
+        :loading="resultLoading"
+        type="primary"
+        icon="VideoPlay"
+        @click="handleQuerySql">
+        {{ $t('operation.run') }}
+      </el-button>
+      <el-dropdown @command="handleChangeLimit">
+        <span class="el-dropdown-link">
+          Limit: {{ limit }}
+          <el-icon class="el-icon--right">
+            <arrow-down />
+          </el-icon>
+        </span>
+        <template #dropdown>
+          <el-dropdown-menu>
+            <el-dropdown-item v-for="l in limits" :key="l" :command="l">
+              Limit: {{ l }}
+            </el-dropdown-item>
+          </el-dropdown-menu>
+        </template>
+      </el-dropdown>
+    </el-space>
+    <section>
+      <MonacoEditor
+        v-model="editorVariables.content"
+        :language="editorVariables.language"
+        :theme="theme"
+        @editor-mounted="editorMounted"
+        @change="handleContentChange"
+        @editor-save="editorSave" />
+    </section>
+    <pre v-show="sqlLog" v-loading="logLoading">{{ sqlLog }}</pre>
+    <el-tabs v-model="activeTab" type="card" class="result-el-tabs">
+      <el-tab-pane
+        v-loading="resultLoading"
+        :label="`Result${sqlResult?.length ? ` (${sqlResult?.length})` : ''}`"
+        name="result">
+        <Result :data="sqlResult" />
+      </el-tab-pane>
+    </el-tabs>
+  </div>
+</template>
+
+<script lang="ts" setup>
+  import MonacoEditor from '@/components/monaco-editor/index.vue'
+  import Result from './Result.vue'
+  import { ref, reactive, onUnmounted, toRaw } from 'vue'
+  import type { Ref } from 'vue'
+  import * as monaco from 'monaco-editor'
+  import { format } from 'sql-formatter'
+  import { ElMessage } from 'element-plus'
+  import { useI18n } from 'vue-i18n'
+  import { getEngineType } from '@/utils/engine'
+  import {
+    openSession,
+    closeSession,
+    runSql,
+    getSqlRowset,
+    getSqlMetadata,
+    log
+  } from '@/api/editor'
+  import type { IResponse, ISqlResult, IFields, ILog } from './types'
+
+  const { t } = useI18n()
+  const param = reactive({
+    engineType: 'SPARK_SQL'
+  })
+  const limit = ref(10)
+  const limits = ref([10, 50, 100])

Review Comment:
   We don't need to bind this limits two-way data binding, simple constants 
should suffice.
   



-- 
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]

Reply via email to