Unverified Commit a2b9e503 authored by aiwenmo's avatar aiwenmo Committed by GitHub

[Optimization-881][datastudio] Optimizate FlinkSql explain exception message (#993)

Co-authored-by: 's avatarwenmo <32723967+wenmo@users.noreply.github.com>
parent 134ee64d
...@@ -20,13 +20,14 @@ ...@@ -20,13 +20,14 @@
import {StateType} from "@/pages/DataStudio/model"; import {StateType} from "@/pages/DataStudio/model";
import {connect} from "umi"; import {connect} from "umi";
import {Button, Tag, Space, Typography, Modal,} from 'antd'; import {Modal, Space, Tag, Typography,} from 'antd';
import {ConsoleSqlOutlined} from "@ant-design/icons"; import {ConsoleSqlOutlined} from "@ant-design/icons";
import ProList from '@ant-design/pro-list'; import ProList from '@ant-design/pro-list';
import {explainSql} from "@/pages/DataStudio/service"; import {explainSql} from "@/pages/DataStudio/service";
import {useRef, useState, useEffect} from "react"; import {useEffect, useState} from "react";
import CodeShow from "@/components/Common/CodeShow";
const {Paragraph,Text} = Typography; const {Paragraph, Text} = Typography;
type ExplainItem = { type ExplainItem = {
index: number; index: number;
...@@ -79,29 +80,24 @@ const StudioExplain = (props: any) => { ...@@ -79,29 +80,24 @@ const StudioExplain = (props: any) => {
setExplainData([]); setExplainData([]);
const result = explainSql(param); const result = explainSql(param);
result.then(res => { result.then(res => {
setExplainData(res.datas); const errorExplainData: [] = [];
let errorCount: number = 0; let errorCount: number = 0;
for (let i in res.datas) { for (let i in res.datas) {
if (!res.datas[i].explainTrue || !res.datas[i].parseTrue) { if (!res.datas[i].explainTrue || !res.datas[i].parseTrue) {
errorExplainData.push(res.datas[i]);
errorCount++; errorCount++;
} }
} }
if (errorCount == 0) { if (errorCount == 0) {
setExplainData(res.datas);
setResult(<Text type="success">全部正确</Text>); setResult(<Text type="success">全部正确</Text>);
} else { } else {
setExplainData(errorExplainData);
setResult(<Text type="danger">存在错误,共计{errorCount}</Text>); setResult(<Text type="danger">存在错误,共计{errorCount}</Text>);
} }
}) })
}, [modalVisible]); }, [modalVisible]);
const renderFooter = () => {
return (
<>
<Button onClick={onClose}>关闭</Button>
</>
);
};
const renderContent = () => { const renderContent = () => {
return ( return (
<> <>
...@@ -144,18 +140,10 @@ const StudioExplain = (props: any) => { ...@@ -144,18 +140,10 @@ const StudioExplain = (props: any) => {
{row.sql} {row.sql}
</Paragraph>) : null </Paragraph>) : null
} }
{row.explain ?
(<Paragraph>
<pre style={{height: '80px'}}>
{row.explain}
</pre>
</Paragraph>) : null
}
{row.error ? {row.error ?
(<Paragraph> (<Paragraph>
<pre style={{height: '80px'}}> <CodeShow code={row.error} language='java'
{row.error} height='500px' theme="vs-dark"/>
</pre>
</Paragraph>) : null </Paragraph>) : null
} }
</> </>
...@@ -189,11 +177,12 @@ const StudioExplain = (props: any) => { ...@@ -189,11 +177,12 @@ const StudioExplain = (props: any) => {
return ( return (
<Modal <Modal
width={800} width={'100%'}
destroyOnClose destroyOnClose
centered
title="FlinkSql 语法和逻辑检查" title="FlinkSql 语法和逻辑检查"
visible={modalVisible} visible={modalVisible}
footer={renderFooter()} footer={false}
onCancel={onClose} onCancel={onClose}
> >
<Paragraph> <Paragraph>
...@@ -204,7 +193,7 @@ const StudioExplain = (props: any) => { ...@@ -204,7 +193,7 @@ const StudioExplain = (props: any) => {
); );
}; };
export default connect(({Studio}: {Studio: StateType}) => ({ export default connect(({Studio}: { Studio: StateType }) => ({
current: Studio.current, current: Studio.current,
currentSession: Studio.currentSession, currentSession: Studio.currentSession,
}))(StudioExplain); }))(StudioExplain);
...@@ -21,13 +21,14 @@ ...@@ -21,13 +21,14 @@
import {Typography} from 'antd'; import {Typography} from 'antd';
import {useEffect, useState} from "react"; import {useEffect, useState} from "react";
import {getData} from "@/components/Common/crud"; import {getData} from "@/components/Common/crud";
import CodeShow from "@/components/Common/CodeShow";
const {Text, Paragraph} = Typography; const {Paragraph} = Typography;
const SqlExport = (props: any) => { const SqlExport = (props: any) => {
const {id} = props; const {id} = props;
const [statement, setStatement] = useState<string>(); const [statement, setStatement] = useState<string>('');
const refreshStatement = async () => { const refreshStatement = async () => {
const msg = await getData('api/task/exportSql', {id: id}); const msg = await getData('api/task/exportSql', {id: id});
...@@ -42,7 +43,8 @@ const SqlExport = (props: any) => { ...@@ -42,7 +43,8 @@ const SqlExport = (props: any) => {
<Paragraph copyable={{text: statement}}> <Paragraph copyable={{text: statement}}>
</Paragraph> </Paragraph>
<Paragraph> <Paragraph>
<pre style={{height: '300px'}}>{statement}</pre> <CodeShow code={statement} language='sql'
height='500px' theme="vs-dark"/>
</Paragraph></>) </Paragraph></>)
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment