Skip to content

Commit

Permalink
[Fix] fix doris datasource get sql ddl and sql query maybe npe (#3181)
Browse files Browse the repository at this point in the history
Co-authored-by: Zzm0809 <[email protected]>
  • Loading branch information
Zzm0809 and Zzm0809 authored Feb 26, 2024
1 parent c754d43 commit 9225519
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ public class SqlGeneration {
value = "Flink SQL Create Statement",
dataType = "String",
notes = "Flink SQL statement for creating a table or view")
private String flinkSqlCreate;
private String flinkSqlCreate = "";

@ApiModelProperty(value = "SQL Select Statement", dataType = "String", notes = "SQL SELECT statement")
private String sqlSelect;
private String sqlSelect = "";

@ApiModelProperty(value = "SQL Create Statement", dataType = "String", notes = "SQL statement for creating a table")
private String sqlCreate;
private String sqlCreate = "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ public String getCreateTableSql(Table table) {

private String genTable(Table table) {
String columnStrs = table.getColumns().stream()
.map(column -> {
return generateColumnSql(column, table.getDriverType());
})
.map(column -> generateColumnSql(column, table.getDriverType()))
.collect(Collectors.joining(",\n"));

List<String> columnKeys = table.getColumns().stream()
Expand Down Expand Up @@ -193,6 +191,9 @@ private String generateColumnSql(Column column, String driverType) {
case MYSQL:
columnType = MysqlType.toDorisType(column.getType(), length, scale);
break;
case DORIS:
columnType = new DorisTypeConvert().convertToDB(column);
break;
case ORACLE:
columnType = OracleType.toDorisType(column.getType(), length, scale);
break;
Expand All @@ -203,7 +204,7 @@ private String generateColumnSql(Column column, String driverType) {
columnType = SqlServerType.toDorisType(column.getType(), length, scale);
break;
default:
String errMsg = "Not support " + driverType + " schema change.";
String errMsg = "Not support " + driverType + " to Doris column type conversion.";
throw new UnsupportedOperationException(errMsg);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ const CodeShowProps = {

const GenSQL: React.FC<GenSQLProps> = (props) => {
const { queryParams, tagDisabled } = props;
const [genSQL, setGenSQL] = useState<Partial<DataSources.SqlGeneration>>({});
const [genSQL, setGenSQL] = useState<DataSources.SqlGeneration>({
flinkSqlCreate: '',
sqlSelect: '',
sqlCreate: ''
});
const [activeKey, setActiveKey] = React.useState<string>('flinkddl');

const queryDDL = useCallback(async () => {
Expand Down Expand Up @@ -92,21 +96,21 @@ const GenSQL: React.FC<GenSQLProps> = (props) => {
const tabList = [
{
key: 'flinkddl',
label: renderLabel(genSQL.flinkSqlCreate || '', 'Flink DDL'),
label: renderLabel(genSQL?.flinkSqlCreate ?? '', 'Flink DDL'),
disabled: tagDisabled,
children: renderContent(genSQL.flinkSqlCreate)
children: renderContent(genSQL?.flinkSqlCreate ?? '')
},
{
key: 'select',
label: renderLabel(genSQL.sqlSelect || '', 'Select'),
label: renderLabel(genSQL?.sqlSelect ?? '', 'Select'),
disabled: tagDisabled,
children: renderContent(genSQL.sqlSelect)
children: renderContent(genSQL?.sqlSelect ?? '')
},
{
key: 'sqlddl',
label: renderLabel(genSQL.sqlCreate || '', 'SQL DDL'),
label: renderLabel(genSQL?.sqlCreate ?? '', 'SQL DDL'),
disabled: tagDisabled,
children: renderContent(genSQL.sqlCreate)
children: renderContent(genSQL?.sqlCreate ?? '')
}
];

Expand All @@ -124,7 +128,7 @@ const GenSQL: React.FC<GenSQLProps> = (props) => {
*/
return (
<>
{genSQL.flinkSqlCreate || genSQL.sqlSelect || genSQL.sqlCreate ? (
{genSQL?.flinkSqlCreate || genSQL?.sqlSelect || genSQL?.sqlCreate ? (
<ProCard tabs={{ ...restTabProps }} />
) : (
<Empty className={'code-content-empty'} description={l('rc.ds.detail.tips')} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const SQLQuery: React.FC<SQLQueryProps> = (props) => {
const [tableData, setTableData] = useState({ columns: [{}], rowData: [{}] });
const [autoCompleteColumns, setAutoCompleteColumns] = useState<DefaultOptionType[]>([]);
const [loading, setLoading] = useState<boolean>(false);
const [errMsg, setErrMsg] = useState<{ isErr: boolean; msg: string }>({
const [responseMsg, setResponseMsg] = useState<{ isErr: boolean; msg: string }>({
isErr: false,
msg: ''
});
Expand All @@ -69,11 +69,15 @@ const SQLQuery: React.FC<SQLQueryProps> = (props) => {
const {
code,
data: { columns, rowData }
} = result; // 获取到的数据
if (code === 1) {
setErrMsg({ isErr: true, msg: result.data.error });
} = result ?? {
code: -1,
data: { columns: [], rowData: [] }
}; // 获取到的数据

if (code && code === 1) {
setResponseMsg({ isErr: true, msg: result.data.error });
} else {
setErrMsg({ isErr: false, msg: '' });
setResponseMsg({ isErr: false, msg: '' });
}
// render columns list
const tableColumns = columns?.map((item: string | number) => ({
Expand All @@ -94,7 +98,7 @@ const SQLQuery: React.FC<SQLQueryProps> = (props) => {
*/
const clearState = () => {
setTableData({ columns: [], rowData: [] });
setErrMsg({ isErr: false, msg: '' });
setResponseMsg({ isErr: false, msg: '' });
setLoading(false);
form.resetFields();
};
Expand All @@ -114,8 +118,8 @@ const SQLQuery: React.FC<SQLQueryProps> = (props) => {
const renderAlert = () => {
return (
<>
{errMsg.isErr ? (
<Alert message='Error' description={errMsg.msg} type='error' showIcon />
{responseMsg.isErr ? (
<Alert message='Error' description={responseMsg.msg} type='error' showIcon />
) : (
<></>
)}
Expand Down
6 changes: 3 additions & 3 deletions dinky-web/src/types/RegCenter/data.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ declare namespace DataSources {
* table columns info
*/
export type SqlGeneration = {
flinkSqlCreate: string;
sqlSelect: string;
sqlCreate: string;
flinkSqlCreate: string | '';
sqlSelect: string | '';
sqlCreate: string | '';
};
}

Expand Down

0 comments on commit 9225519

Please sign in to comment.