Unverified Commit 53f8f662 authored by suxinshuo's avatar suxinshuo Committed by GitHub

[Fix-3494][metadata] Fix clickhouse query table description information failure (#3504)

parent 26aa980e
...@@ -38,6 +38,7 @@ public enum ColumnType { ...@@ -38,6 +38,7 @@ public enum ColumnType {
INT("int", "INT NOT NULL"), INT("int", "INT NOT NULL"),
JAVA_LANG_LONG("java.lang.Long", "BIGINT"), JAVA_LANG_LONG("java.lang.Long", "BIGINT"),
LONG("long", "BIGINT NOT NULL"), LONG("long", "BIGINT NOT NULL"),
BIG_INTEGER("java.math.BigInteger", "BIGINT"),
JAVA_LANG_FLOAT("java.lang.Float", "FLOAT"), JAVA_LANG_FLOAT("java.lang.Float", "FLOAT"),
FLOAT("float", "FLOAT NOT NULL"), FLOAT("float", "FLOAT NOT NULL"),
JAVA_LANG_DOUBLE("java.lang.Double", "DOUBLE"), JAVA_LANG_DOUBLE("java.lang.Double", "DOUBLE"),
......
...@@ -20,6 +20,10 @@ ...@@ -20,6 +20,10 @@
package org.dinky.metadata.convert; package org.dinky.metadata.convert;
import org.dinky.data.enums.ColumnType; import org.dinky.data.enums.ColumnType;
import org.dinky.data.model.Column;
import org.dinky.metadata.enums.ClickHouseDataTypeEnum;
import java.util.Objects;
/** /**
* ClickHouseTypeConvert * ClickHouseTypeConvert
...@@ -28,30 +32,20 @@ import org.dinky.data.enums.ColumnType; ...@@ -28,30 +32,20 @@ import org.dinky.data.enums.ColumnType;
*/ */
public class ClickHouseTypeConvert extends AbstractJdbcTypeConvert { public class ClickHouseTypeConvert extends AbstractJdbcTypeConvert {
// Use mysql now,and welcome to fix it. @Override
public ClickHouseTypeConvert() { public ColumnType convert(Column column) {
this.convertMap.clear(); if (Objects.isNull(column)) {
register("tinyint", ColumnType.BYTE); return ColumnType.STRING;
register("smallint", ColumnType.SHORT, ColumnType.JAVA_LANG_SHORT); }
register("bigint unsigned", ColumnType.DECIMAL); String type = column.getType();
register("numeric", ColumnType.DECIMAL); if (Objects.isNull(type)) {
register("decimal", ColumnType.DECIMAL); return ColumnType.STRING;
register("bigint", ColumnType.LONG, ColumnType.JAVA_LANG_LONG); }
register("int unsigned", ColumnType.LONG); ColumnType columnType = ClickHouseDataTypeEnum.of(type).getColumnType();
register("float", ColumnType.FLOAT, ColumnType.JAVA_LANG_FLOAT); if (Objects.nonNull(columnType)) {
register("double", ColumnType.DOUBLE, ColumnType.JAVA_LANG_DOUBLE); return columnType;
register("boolean", ColumnType.BOOLEAN, ColumnType.JAVA_LANG_BOOLEAN); }
register("tinyint(1)", ColumnType.BOOLEAN, ColumnType.JAVA_LANG_BOOLEAN); return ColumnType.STRING;
register("datetime", ColumnType.TIMESTAMP);
register("date", ColumnType.DATE);
register("time", ColumnType.TIME);
register("char", ColumnType.STRING);
register("text", ColumnType.STRING);
register("binary", ColumnType.BYTES);
register("blob", ColumnType.BYTES);
register("int", ColumnType.INT, ColumnType.INTEGER);
register("mediumint", ColumnType.INT, ColumnType.INTEGER);
register("smallint unsigned", ColumnType.INT, ColumnType.INTEGER);
} }
@Override @Override
......
...@@ -27,6 +27,7 @@ import org.dinky.metadata.ast.Clickhouse20CreateTableStatement; ...@@ -27,6 +27,7 @@ import org.dinky.metadata.ast.Clickhouse20CreateTableStatement;
import org.dinky.metadata.config.AbstractJdbcConfig; import org.dinky.metadata.config.AbstractJdbcConfig;
import org.dinky.metadata.convert.ClickHouseTypeConvert; import org.dinky.metadata.convert.ClickHouseTypeConvert;
import org.dinky.metadata.convert.ITypeConvert; import org.dinky.metadata.convert.ITypeConvert;
import org.dinky.metadata.enums.ClickHouseDataTypeEnum;
import org.dinky.metadata.enums.DriverType; import org.dinky.metadata.enums.DriverType;
import org.dinky.metadata.parser.Clickhouse20StatementParser; import org.dinky.metadata.parser.Clickhouse20StatementParser;
import org.dinky.metadata.query.ClickHouseQuery; import org.dinky.metadata.query.ClickHouseQuery;
...@@ -41,6 +42,7 @@ import java.util.ArrayList; ...@@ -41,6 +42,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
...@@ -51,11 +53,14 @@ import com.alibaba.druid.sql.ast.statement.SQLSelectStatement; ...@@ -51,11 +53,14 @@ import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
import com.alibaba.druid.sql.parser.ParserException; import com.alibaba.druid.sql.parser.ParserException;
import com.alibaba.druid.sql.parser.Token; import com.alibaba.druid.sql.parser.Token;
import lombok.extern.slf4j.Slf4j;
/** /**
* ClickHouseDriver * ClickHouseDriver
* *
* @since 2021/7/21 17:14 * @since 2021/7/21 17:14
*/ */
@Slf4j
public class ClickHouseDriver extends AbstractJdbcDriver { public class ClickHouseDriver extends AbstractJdbcDriver {
@Override @Override
...@@ -196,69 +201,36 @@ public class ClickHouseDriver extends AbstractJdbcDriver { ...@@ -196,69 +201,36 @@ public class ClickHouseDriver extends AbstractJdbcDriver {
field.setName(columnName); field.setName(columnName);
if (columnList.contains(dbQuery.columnType())) { if (columnList.contains(dbQuery.columnType())) {
String columnType = results.getString(dbQuery.columnType()); String columnType = results.getString(dbQuery.columnType());
if (columnType.indexOf("Nullable") >= 0) { field.setNullable(ClickHouseDataTypeEnum.isNullable(columnType));
field.setNullable(true);
columnType = columnType.replaceAll("Nullable\\(", "").replaceAll("\\)", "");
}
if (columnType.contains("(")) {
String type = columnType.replaceAll("\\(.*\\)", "");
if (!columnType.contains(",")) {
Integer length = Integer.valueOf(columnType.replaceAll("\\D", ""));
field.setLength(length);
} else {
// some database does not have precision
if (dbQuery.precision() != null) {
// 例如浮点类型的长度和精度是一样的,decimal(10,2)
field.setLength(results.getInt(dbQuery.precision()));
}
}
field.setType(type);
} else {
field.setType(columnType); field.setType(columnType);
} }
}
if (columnList.contains(dbQuery.columnComment()) if (columnList.contains(dbQuery.columnComment())
&& Asserts.isNotNull(results.getString(dbQuery.columnComment()))) { && Asserts.isNotNull(results.getString(dbQuery.columnComment()))) {
String columnComment = String columnComment =
results.getString(dbQuery.columnComment()).replaceAll("\"|'", ""); results.getString(dbQuery.columnComment()).replaceAll("\"|'", "");
field.setComment(columnComment); field.setComment(columnComment);
} }
if (columnList.contains(dbQuery.columnLength())) {
int length = results.getInt(dbQuery.columnLength());
if (!results.wasNull()) {
field.setLength(length);
}
}
if (columnList.contains(dbQuery.characterSet())) {
field.setCharacterSet(results.getString(dbQuery.characterSet()));
}
if (columnList.contains(dbQuery.collation())) {
field.setCollation(results.getString(dbQuery.collation()));
}
if (columnList.contains(dbQuery.columnPosition())) { if (columnList.contains(dbQuery.columnPosition())) {
field.setPosition(results.getInt(dbQuery.columnPosition())); field.setPosition(results.getInt(dbQuery.columnPosition()));
} }
if (columnList.contains(dbQuery.precision())) { ClickHouseDataTypeEnum clickHouseDataTypeEnum = ClickHouseDataTypeEnum.of(field.getType());
field.setPrecision(results.getInt(dbQuery.precision())); Integer length = clickHouseDataTypeEnum.getLength(field.getType());
} if (Objects.nonNull(length)) {
if (columnList.contains(dbQuery.scale())) { field.setLength(length);
field.setScale(results.getInt(dbQuery.scale()));
}
if (columnList.contains(dbQuery.defaultValue())) {
field.setDefaultValue(results.getString(dbQuery.defaultValue()));
} }
if (columnList.contains(dbQuery.autoIncrement())) { Integer scale = clickHouseDataTypeEnum.getScale(field.getType());
field.setAutoIncrement( if (Objects.nonNull(scale)) {
Asserts.isEqualsIgnoreCase(results.getString(dbQuery.autoIncrement()), "auto_increment")); field.setScale(scale);
} }
if (columnList.contains(dbQuery.defaultValue())) { Integer precision = clickHouseDataTypeEnum.getPrecision(field.getType());
field.setDefaultValue(results.getString(dbQuery.defaultValue())); if (Objects.nonNull(precision)) {
field.setPrecision(precision);
} }
field.setJavaType(getTypeConvert().convert(field, config)); field.setJavaType(getTypeConvert().convert(field));
columns.add(field); columns.add(field);
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); log.error("ClickHouseDriver listColumns error.", e);
} finally { } finally {
close(preparedStatement, results); close(preparedStatement, results);
} }
......
/*
*
* 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.
*
*/
package org.dinky.metadata.enums;
import org.dinky.data.enums.ColumnType;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* ClickHouseColTypeEnum
*
* @since 2024/5/17 11:28
*/
@Getter
@AllArgsConstructor
public enum ClickHouseDataTypeEnum {
Nullable("Nullable", Boolean.TRUE, 0, null, null),
Array("Array", Boolean.TRUE, 0, ColumnType.T, ColumnType.T),
Map("Map", Boolean.TRUE, 0, ColumnType.MAP, ColumnType.MAP),
UInt8("UInt8", Boolean.FALSE, 0, ColumnType.SHORT, ColumnType.JAVA_LANG_SHORT),
UInt16("UInt16", Boolean.FALSE, 0, ColumnType.INT, ColumnType.INTEGER),
UInt32("UInt32", Boolean.FALSE, 0, ColumnType.LONG, ColumnType.JAVA_LANG_LONG),
UInt64("UInt64", Boolean.FALSE, 0, ColumnType.BIG_INTEGER, ColumnType.BIG_INTEGER),
UInt128("UInt128", Boolean.FALSE, 0, ColumnType.BIG_INTEGER, ColumnType.BIG_INTEGER),
UInt256("UInt256", Boolean.FALSE, 0, ColumnType.BIG_INTEGER, ColumnType.BIG_INTEGER),
Int8("Int8", Boolean.FALSE, 0, ColumnType.BYTE, ColumnType.JAVA_LANG_BYTE),
Int16("Int16", Boolean.FALSE, 0, ColumnType.SHORT, ColumnType.JAVA_LANG_SHORT),
Int32("Int32", Boolean.FALSE, 0, ColumnType.INT, ColumnType.INTEGER),
Int64("Int64", Boolean.FALSE, 0, ColumnType.LONG, ColumnType.JAVA_LANG_LONG),
Int128("Int128", Boolean.FALSE, 0, ColumnType.BIG_INTEGER, ColumnType.BIG_INTEGER),
Int256("Int256", Boolean.FALSE, 0, ColumnType.BIG_INTEGER, ColumnType.BIG_INTEGER),
Float32("Float32", Boolean.FALSE, 0, ColumnType.FLOAT, ColumnType.JAVA_LANG_FLOAT),
Float64("Float64", Boolean.FALSE, 0, ColumnType.DOUBLE, ColumnType.JAVA_LANG_DOUBLE),
String("String", Boolean.FALSE, 0, ColumnType.STRING, ColumnType.STRING),
FixedString("FixedString", Boolean.TRUE, 0, ColumnType.STRING, ColumnType.STRING) {
@Override
public Integer getLength(String dataType) {
// FixedString(N)
if (StrUtil.isBlank(dataType)) {
return null;
}
String lengthStr = removeType(dataType, Lists.newArrayList(Nullable, FixedString));
if (!NumberUtil.isNumber(lengthStr)) {
return null;
}
return Integer.parseInt(lengthStr);
}
},
Bool("Bool", Boolean.FALSE, 0, ColumnType.BOOLEAN, ColumnType.JAVA_LANG_BOOLEAN),
Date("Date", Boolean.FALSE, 0, ColumnType.LOCAL_DATE, ColumnType.LOCAL_DATE),
Date32("Date32", Boolean.FALSE, 0, ColumnType.LOCAL_DATE, ColumnType.LOCAL_DATE),
DateTime("DateTime", Boolean.TRUE, 0, ColumnType.LOCAL_DATETIME, ColumnType.LOCAL_DATETIME),
DateTime64("DateTime64", Boolean.TRUE, 1, ColumnType.LOCAL_DATETIME, ColumnType.LOCAL_DATETIME),
Decimal("Decimal", Boolean.TRUE, 0, ColumnType.DECIMAL, ColumnType.DECIMAL) {
@Override
public Integer getScale(String dataType) {
// Decimal Decimal(P) Decimal(P, S)
if (StrUtil.isBlank(dataType) || !dataType.contains("(")) {
return null;
}
String ps = removeType(dataType, Lists.newArrayList(Nullable, Decimal));
if (!StrUtil.contains(ps, ",")) {
// only precision, scale is default 0
return 0;
}
List<String> psSplit = StrUtil.split(ps, ",");
String sStr = psSplit.get(1).trim();
if (!NumberUtil.isNumber(sStr)) {
return null;
}
return Integer.parseInt(sStr);
}
@Override
public Integer getPrecision(java.lang.String dataType) {
// Decimal Decimal(P) Decimal(P, S)
if (StrUtil.isBlank(dataType) || !dataType.contains("(")) {
return null;
}
String ps = removeType(dataType, Lists.newArrayList(Nullable, Decimal));
String pStr;
if (!StrUtil.contains(ps, ",")) {
pStr = ps;
} else {
List<String> psSplit = StrUtil.split(ps, ",");
pStr = psSplit.get(0).trim();
}
if (!NumberUtil.isNumber(pStr)) {
return null;
}
return Integer.parseInt(pStr);
}
},
Decimal32("Decimal32", Boolean.TRUE, 1, ColumnType.DECIMAL, ColumnType.DECIMAL) {
@Override
public Integer getScale(String dataType) {
// Decimal32(S)
if (StrUtil.isBlank(dataType) || !dataType.contains("(")) {
return null;
}
String sStr = removeType(dataType, Lists.newArrayList(Nullable, Decimal32));
if (!NumberUtil.isNumber(sStr)) {
return null;
}
return Integer.parseInt(sStr);
}
@Override
public Integer getPrecision(String dataType) {
Integer scale = getScale(dataType);
if (Objects.isNull(scale)) {
return null;
}
return 9 - scale;
}
},
Decimal64("Decimal64", Boolean.TRUE, 2, ColumnType.DECIMAL, ColumnType.DECIMAL) {
@Override
public Integer getScale(String dataType) {
// Decimal64(S)
if (StrUtil.isBlank(dataType) || !dataType.contains("(")) {
return null;
}
String sStr = removeType(dataType, Lists.newArrayList(Nullable, Decimal64));
if (!NumberUtil.isNumber(sStr)) {
return null;
}
return Integer.parseInt(sStr);
}
@Override
public Integer getPrecision(String dataType) {
Integer scale = getScale(dataType);
if (Objects.isNull(scale)) {
return null;
}
return 18 - scale;
}
},
Decimal128("Decimal128", Boolean.TRUE, 3, ColumnType.DECIMAL, ColumnType.DECIMAL) {
@Override
public Integer getScale(String dataType) {
// Decimal128(S)
if (StrUtil.isBlank(dataType) || !dataType.contains("(")) {
return null;
}
String sStr = removeType(dataType, Lists.newArrayList(Nullable, Decimal128));
if (!NumberUtil.isNumber(sStr)) {
return null;
}
return Integer.parseInt(sStr);
}
@Override
public Integer getPrecision(String dataType) {
Integer scale = getScale(dataType);
if (Objects.isNull(scale)) {
return null;
}
return 38 - scale;
}
},
Decimal256("Decimal256", Boolean.TRUE, 4, ColumnType.DECIMAL, ColumnType.DECIMAL) {
@Override
public Integer getScale(String dataType) {
// Decimal256(S)
if (StrUtil.isBlank(dataType) || !dataType.contains("(")) {
return null;
}
String sStr = removeType(dataType, Lists.newArrayList(Nullable, Decimal256));
if (!NumberUtil.isNumber(sStr)) {
return null;
}
return Integer.parseInt(sStr);
}
@Override
public Integer getPrecision(String dataType) {
Integer scale = getScale(dataType);
if (Objects.isNull(scale)) {
return null;
}
return 76 - scale;
}
},
UUID("UUID", Boolean.FALSE, 0, ColumnType.STRING, ColumnType.STRING),
// Enum Enum8 Enum16 -> String
Enum("Enum", Boolean.TRUE, 0, ColumnType.STRING, ColumnType.STRING),
// Tuple -> Json String
Tuple("Tuple", Boolean.TRUE, 0, ColumnType.STRING, ColumnType.STRING);
private final String name;
private final Boolean prefixMatch;
/**
* when multiple type enumerations are matched,
* the one with the largest priority is taken.
*/
private final Integer matchPriority;
private final ColumnType columnType;
private final ColumnType nullColumnType;
/**
* cache data type map
*/
private static final Map<String, ClickHouseDataTypeEnum> CK_DATA_TYPE_MAP = Maps.newHashMap();
public Integer getLength(String dataType) {
return null;
}
public Integer getPrecision(String dataType) {
return null;
}
public Integer getScale(String dataType) {
return null;
}
public static String removeType(String dataType, List<ClickHouseDataTypeEnum> ckColTypeEnums) {
if (StrUtil.isBlank(dataType) || CollUtil.isEmpty(ckColTypeEnums)) {
return dataType;
}
String dataTypeRep = dataType.replaceAll("\\)", "").toLowerCase();
for (ClickHouseDataTypeEnum ckColTypeEnum : ckColTypeEnums) {
dataTypeRep = dataTypeRep.replaceAll(ckColTypeEnum.getName().toLowerCase() + "\\(", "");
}
return StrUtil.trim(dataTypeRep);
}
private static List<ClickHouseDataTypeEnum> match(String dataType) {
String finalType =
ClickHouseDataTypeEnum.removeType(dataType, Lists.newArrayList(ClickHouseDataTypeEnum.Nullable));
return Arrays.stream(ClickHouseDataTypeEnum.values())
.filter(clickHouseDataTypeEnum -> {
String name = clickHouseDataTypeEnum.getName();
Boolean prefixMatch = clickHouseDataTypeEnum.getPrefixMatch();
if (BooleanUtil.isTrue(prefixMatch)) {
return StrUtil.startWithIgnoreCase(finalType, name);
}
return StrUtil.equalsIgnoreCase(finalType, name);
})
.collect(Collectors.toList());
}
/**
* converts given type name to clickhouse data type.
*/
public static ClickHouseDataTypeEnum of(String dataType) {
if (Objects.isNull(dataType)) {
return ClickHouseDataTypeEnum.String;
}
ClickHouseDataTypeEnum ckDataTypeEnum = CK_DATA_TYPE_MAP.get(dataType);
if (Objects.nonNull(ckDataTypeEnum)) {
return ckDataTypeEnum;
}
ClickHouseDataTypeEnum clickHouseDataTypeEnum =
Optional.ofNullable(match(dataType)).orElse(Lists.newArrayList()).stream()
.max(Comparator.comparing(ClickHouseDataTypeEnum::getMatchPriority))
.orElse(ClickHouseDataTypeEnum.String);
CK_DATA_TYPE_MAP.put(dataType, clickHouseDataTypeEnum);
return clickHouseDataTypeEnum;
}
public static Boolean isNullable(String dataType) {
if (StrUtil.isBlank(dataType)) {
return Boolean.FALSE;
}
return StrUtil.startWithIgnoreCase(dataType.trim(), Nullable.getName());
}
}
...@@ -39,7 +39,8 @@ public class ClickHouseQuery extends AbstractDBQuery { ...@@ -39,7 +39,8 @@ public class ClickHouseQuery extends AbstractDBQuery {
*/ */
@Override @Override
public String tablesSql(String schemaName) { public String tablesSql(String schemaName) {
return "select name from system.tables where 1=1 and database='" + schemaName + "'"; return "select name, total_rows, engine, metadata_modification_time, comment "
+ "from system.tables where 1=1 and database='" + schemaName + "'";
} }
/** /**
...@@ -51,11 +52,7 @@ public class ClickHouseQuery extends AbstractDBQuery { ...@@ -51,11 +52,7 @@ public class ClickHouseQuery extends AbstractDBQuery {
*/ */
@Override @Override
public String columnsSql(String schemaName, String tableName) { public String columnsSql(String schemaName, String tableName) {
return "select * from system.columns where 1=1 and database='" return "select * from system.columns where 1=1 and database='" + schemaName + "' and table='" + tableName + "'";
+ schemaName
+ "' and table='"
+ tableName
+ "'";
} }
@Override @Override
...@@ -107,4 +104,24 @@ public class ClickHouseQuery extends AbstractDBQuery { ...@@ -107,4 +104,24 @@ public class ClickHouseQuery extends AbstractDBQuery {
public String isPK() { public String isPK() {
return "1"; return "1";
} }
@Override
public String columnPosition() {
return "position";
}
@Override
public String engine() {
return "engine";
}
@Override
public String rows() {
return "total_rows";
}
@Override
public String updateTime() {
return "metadata_modification_time";
}
} }
/*
*
* 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.
*
*/
package org.dinky.metadata.enums;
import static org.dinky.metadata.enums.ClickHouseDataTypeEnum.*;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class ClickHouseDataTypeEnumTest {
@Test
public void removeTypeTest() {
String dataType = "Array(Int32)";
String res = ClickHouseDataTypeEnum.removeType(dataType, Lists.newArrayList(Nullable, Array));
assertEquals("int32", res);
}
@Test
public void removeTypeTest2() {
String dataType = "FixedString(6)";
String res = ClickHouseDataTypeEnum.removeType(dataType, Lists.newArrayList(Nullable, FixedString));
assertEquals("6", res);
}
@Test
public void removeTypeTest3() {
String dataType = "Decimal(6)";
String res = ClickHouseDataTypeEnum.removeType(dataType, Lists.newArrayList(Nullable, Decimal));
assertEquals("6", res);
}
@Test
public void ofTest() {
String dataType = "Decimal(6)";
ClickHouseDataTypeEnum res = of(dataType);
assertEquals(Decimal, res);
}
@Test
public void ofTest2() {
String dataType = "Decimal32(6)";
ClickHouseDataTypeEnum res = of(dataType);
assertEquals(Decimal32, res);
}
@Test
public void ofTest4() {
String dataType = "UInt32";
ClickHouseDataTypeEnum res = of(dataType);
assertEquals(UInt32, res);
}
@Test
public void getLengthTest() {
Integer length = FixedString.getLength("FixedString(10)");
assertEquals(10, length.intValue());
}
@Test
public void getScaleTest() {
Integer scale = Decimal.getScale("Decimal(10, 2)");
assertEquals(2, scale.intValue());
}
@Test
public void getPrecisionTest() {
Integer precision = Decimal.getPrecision("Decimal(10, 2)");
assertEquals(10, precision.intValue());
}
}
...@@ -250,6 +250,7 @@ const Result = (props: any) => { ...@@ -250,6 +250,7 @@ const Result = (props: any) => {
<Table <Table
columns={getColumns(data.columns)} columns={getColumns(data.columns)}
size='small' size='small'
scroll={{ x: 'max-content' }}
dataSource={data.rowData?.map((item: any, index: number) => { dataSource={data.rowData?.map((item: any, index: number) => {
return { ...item, key: index }; return { ...item, key: index };
})} })}
......
...@@ -150,6 +150,7 @@ const SQLQuery: React.FC<SQLQueryProps> = (props) => { ...@@ -150,6 +150,7 @@ const SQLQuery: React.FC<SQLQueryProps> = (props) => {
loading={loading} loading={loading}
{...PROTABLE_OPTIONS_PUBLIC} {...PROTABLE_OPTIONS_PUBLIC}
size={'small'} size={'small'}
scroll={{ x: 'max-content' }}
search={false} search={false}
pagination={{ pagination={{
defaultPageSize: 15, defaultPageSize: 15,
......
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