Skip to content

Commit 73932e7

Browse files
authored
information_schema.tables.table_type changed from Enum8 to String (#218)
* The type of field information_schema.tables.table_type changed from Enum8 to String (#199) * The type of field information_schema.tables.table_type changed from Enum8 to String (#199)
1 parent e144a84 commit 73932e7

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

clickhouse.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ type Config struct {
3030
DefaultCompression string // default compression algorithm. LZ4 is lossless
3131
DefaultIndexType string // index stores extremes of the expression
3232
DefaultTableEngineOpts string
33+
34+
InformationSchemaTablesTableTypeString bool // information_schema.tables.table_type is String
3335
}
3436

3537
type Dialector struct {
@@ -112,6 +114,11 @@ func (dialector *Dialector) Initialize(db *gorm.DB) (err error) {
112114
if versionNoPrecisionColumn.Check(dbversion) {
113115
dialector.DontSupportColumnPrecision = true
114116
}
117+
118+
versionTableType, _ := version.NewConstraint(">= 23.9")
119+
if versionTableType.Check(dbversion) {
120+
dialector.Config.InformationSchemaTablesTableTypeString = true
121+
}
115122
}
116123
}
117124

migrator.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,25 @@ func (m Migrator) HasTable(value interface{}) bool {
190190
return count > 0
191191
}
192192

193+
// GetTables
194+
// clickhouse version 23.9 changelog
195+
// Made the views in schema information_schema more compatible with the equivalent views in MySQL
196+
// (i.e. modified and extended them) up to a point where Tableau Online is able to connect to ClickHouse.
197+
// More specifically:
198+
// 1. The type of field information_schema.tables.table_type changed from Enum8 to String.
199+
// 2. Added fields table_comment and table_collation to view information_schema.table.
200+
// 3. Added views information_schema.key_column_usage and referential_constraints.
201+
// 4. Replaced uppercase aliases in information_schema views with concrete uppercase columns.
202+
// https://github.com/ClickHouse/ClickHouse/pull/54773
203+
//
204+
// version < 23.9 table_type Enum8('BASE TABLE' = 1, 'VIEW' = 2, 'FOREIGN TABLE' = 3, 'LOCAL TEMPORARY' = 4, 'SYSTEM VIEW' = 5)
205+
// version >= 23.9 table_type String
193206
func (m Migrator) GetTables() (tableList []string, err error) {
194-
// table_type Enum8('BASE TABLE' = 1, 'VIEW' = 2, 'FOREIGN TABLE' = 3, 'LOCAL TEMPORARY' = 4, 'SYSTEM VIEW' = 5)
207+
if m.Dialector.Config.InformationSchemaTablesTableTypeString {
208+
err = m.DB.Raw("SELECT TABLE_NAME FROM information_schema.tables where table_schema=? and table_type ='BASE TABLE'", m.CurrentDatabase()).Scan(&tableList).Error
209+
return
210+
}
211+
195212
err = m.DB.Raw("SELECT TABLE_NAME FROM information_schema.tables where table_schema=? and table_type =1", m.CurrentDatabase()).Scan(&tableList).Error
196213
return
197214
}

0 commit comments

Comments
 (0)