@@ -20,11 +20,11 @@ def configuration_schema(cls):
20
20
"type" : "object" ,
21
21
"properties" : {
22
22
"host" : {"type" : "string" , "default" : "localhost" },
23
- "port" : {"type" : "int " , "default" : 8000 },
23
+ "port" : {"type" : "string " , "default" : " 8000" },
24
24
"username" : {"type" : "string" },
25
25
"password" : {"type" : "string" , "default" : "" },
26
26
"database" : {"type" : "string" },
27
- "secure" : {"type" : "string " , "default" : False },
27
+ "secure" : {"type" : "boolean " , "default" : False },
28
28
},
29
29
"order" : ["username" , "password" , "host" , "port" , "database" ],
30
30
"required" : ["username" , "database" ],
@@ -37,7 +37,7 @@ def name(cls):
37
37
38
38
@classmethod
39
39
def type (cls ):
40
- return "Databend "
40
+ return "databend "
41
41
42
42
@classmethod
43
43
def enabled (cls ):
@@ -61,12 +61,12 @@ def _define_column_type(column_type):
61
61
return TYPE_STRING
62
62
63
63
def run_query (self , query , user ):
64
- host = ( self .configuration .get ("host" ) or "localhost" ),
65
- port = ( self .configuration .get ("port" ) or 8000 ),
66
- username = ( self .configuration .get ("username" ) or None ),
67
- password = ( self .configuration .get ("password" ) or None ),
68
- database = ( self .configuration .get ("database" ) or None ),
69
- secure = ( self .configuration .get ("secure" ) or False ),
64
+ host = self .configuration .get ("host" ) or "localhost"
65
+ port = self .configuration .get ("port" ) or " 8000"
66
+ username = self .configuration .get ("username" ) or "root"
67
+ password = self .configuration .get ("password" ) or ""
68
+ database = self .configuration .get ("database" ) or "default"
69
+ secure = self .configuration .get ("secure" ) or False
70
70
connection = connector .connect (f"databend://{ username } :{ password } @{ host } :{ port } /{ database } ?secure={ secure } " )
71
71
cursor = connection .cursor ()
72
72
@@ -87,6 +87,33 @@ def run_query(self, query, user):
87
87
88
88
return json_data , error
89
89
90
+ def get_schema (self , get_stats = False ):
91
+ query = """
92
+ SELECT TABLE_SCHEMA,
93
+ TABLE_NAME,
94
+ COLUMN_NAME
95
+ FROM INFORMATION_SCHEMA.COLUMNS
96
+ WHERE TABLE_SCHEMA NOT IN ('information_schema', 'system')
97
+ """
98
+
99
+ results , error = self .run_query (query , None )
100
+
101
+ if error is not None :
102
+ self ._handle_run_query_error (error )
103
+
104
+ schema = {}
105
+ results = json_loads (results )
106
+
107
+ for row in results ["rows" ]:
108
+ table_name = "{}.{}" .format (row ["table_schema" ], row ["table_name" ])
109
+
110
+ if table_name not in schema :
111
+ schema [table_name ] = {"name" : table_name , "columns" : []}
112
+
113
+ schema [table_name ]["columns" ].append (row ["column_name" ])
114
+
115
+ return list (schema .values ())
116
+
90
117
def _get_tables (self ):
91
118
query = """
92
119
SELECT TABLE_SCHEMA,
0 commit comments