Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dinky
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wangpeng
dinky
Commits
53f8f662
Unverified
Commit
53f8f662
authored
May 20, 2024
by
suxinshuo
Committed by
GitHub
May 20, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Fix-3494][metadata] Fix clickhouse query table description information failure (#3504)
Co-authored-by:
suxinshuo
<
suxinshuo@itiger.com
>
parent
26aa980e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
156 additions
and
77 deletions
+156
-77
ColumnType.java
...common/src/main/java/org/dinky/data/enums/ColumnType.java
+1
-0
ClickHouseTypeConvert.java
...ava/org/dinky/metadata/convert/ClickHouseTypeConvert.java
+18
-24
ClickHouseDriver.java
...main/java/org/dinky/metadata/driver/ClickHouseDriver.java
+19
-47
ClickHouseDataTypeEnum.java
...java/org/dinky/metadata/enums/ClickHouseDataTypeEnum.java
+0
-0
ClickHouseQuery.java
...c/main/java/org/dinky/metadata/query/ClickHouseQuery.java
+23
-6
ClickHouseDataTypeEnumTest.java
.../org/dinky/metadata/enums/ClickHouseDataTypeEnumTest.java
+93
-0
index.tsx
...web/src/pages/DataStudio/BottomContainer/Result/index.tsx
+1
-0
index.tsx
...nents/DataSourceDetail/RightTagsRouter/SQLQuery/index.tsx
+1
-0
No files found.
dinky-common/src/main/java/org/dinky/data/enums/ColumnType.java
View file @
53f8f662
...
@@ -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"
),
...
...
dinky-metadata/dinky-metadata-clickhouse/src/main/java/org/dinky/metadata/convert/ClickHouseTypeConvert.java
View file @
53f8f662
...
@@ -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
...
...
dinky-metadata/dinky-metadata-clickhouse/src/main/java/org/dinky/metadata/driver/ClickHouseDriver.java
View file @
53f8f662
...
@@ -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,26 +201,8 @@ public class ClickHouseDriver extends AbstractJdbcDriver {
...
@@ -196,26 +201,8 @@ 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
);
field
.
setType
(
columnType
);
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
);
}
}
}
if
(
columnList
.
contains
(
dbQuery
.
columnComment
())
if
(
columnList
.
contains
(
dbQuery
.
columnComment
())
&&
Asserts
.
isNotNull
(
results
.
getString
(
dbQuery
.
columnComment
())))
{
&&
Asserts
.
isNotNull
(
results
.
getString
(
dbQuery
.
columnComment
())))
{
...
@@ -223,42 +210,27 @@ public class ClickHouseDriver extends AbstractJdbcDriver {
...
@@ -223,42 +210,27 @@ public class ClickHouseDriver extends AbstractJdbcDriver {
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
);
}
}
...
...
dinky-metadata/dinky-metadata-clickhouse/src/main/java/org/dinky/metadata/enums/ClickHouseDataTypeEnum.java
0 → 100644
View file @
53f8f662
This diff is collapsed.
Click to expand it.
dinky-metadata/dinky-metadata-clickhouse/src/main/java/org/dinky/metadata/query/ClickHouseQuery.java
View file @
53f8f662
...
@@ -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"
;
}
}
}
dinky-metadata/dinky-metadata-clickhouse/src/test/java/org/dinky/metadata/enums/ClickHouseDataTypeEnumTest.java
0 → 100644
View file @
53f8f662
/*
*
* 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
());
}
}
dinky-web/src/pages/DataStudio/BottomContainer/Result/index.tsx
View file @
53f8f662
...
@@ -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
};
})
}
})
}
...
...
dinky-web/src/pages/RegCenter/DataSource/components/DataSourceDetail/RightTagsRouter/SQLQuery/index.tsx
View file @
53f8f662
...
@@ -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
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment