tongwl commented on code in PR #5616: URL: https://github.com/apache/kyuubi/pull/5616#discussion_r1382932060
########## kyuubi-server/web-ui/src/views/editor/components/Editor.vue: ########## @@ -0,0 +1,273 @@ +<!-- +* 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" + disabled + :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 [10, 50, 100]" :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, + getLog + } 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 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(() => { + ElMessage({ Review Comment: @zwangsheng Certainly, got your point, what you think is the api error message might be helpful to users, we also need it! If we want to display all the error info for the APIs through the log, there might be some issues here: The current design for executing SQL is as follows: * First, we call the openSession API, which returns the sessionIdentifier. * Then insert the returned sessionIdentifier into the second API, runSql, which returns the runSqlIdentifier. These two steps must be executed synchronously because they are dependent on each other. After the above steps, there are two more steps remaining: * Retrieving the SQL's return results (here, there are two APIs, one for getting the table's field names, and one for getting the table's field values). * Getting the SQL log. Here, considering the user experience, we don't need to make the APIs execute synchronously. That is, getting the SQL results and getting the SQL log will be sent asynchronously to the service, as the SQL log API doesn't need to wait for the SQL result, and the SQL result API doesn't need to wait for the SQL log. Now, here's the issue: Because the last three APIs are asynchronous, if we only overwrite their error information into the log, it might provide a poor user experience. For example, suppose the getSqlResult API returns an error in 30 seconds (it could be two errors), and it logs the error, then user is watching the log, but suddenly the log gets overwritten because at 45 seconds, the getSqlLog also sends logs. Appending the log to the API isn't good enough either because the log display might not be very clear. **If this error log is useful for user, can we consider this design below?** * The log section will only display query log information. * Error messages will be placed in the error box so that users can clearly see the error content and list error messages from multiple APIs as a reference. (see screenshot) Thanks. -- 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]
