@@ -97,9 +97,13 @@ export const QUERY_SYNTAX = {
9797 pg : 'pg' ,
9898} as const ;
9999
100+ export const getYQLColumnType = ( type : string ) : YQLType => {
101+ return type . replace ( / \? $ / , '' ) as YQLType ;
102+ } ;
103+
100104// eslint-disable-next-line complexity
101105export const getColumnType = ( type : string ) => {
102- switch ( type . replace ( / \? $ / , '' ) ) {
106+ switch ( getYQLColumnType ( type ) ) {
103107 case YQLType . Bool :
104108 return 'boolean' ;
105109 case YQLType . Int8 :
@@ -134,6 +138,50 @@ export const getColumnType = (type: string) => {
134138 }
135139} ;
136140
141+ const columnTypeToDefaultWidth : Record < YQLType , number > = {
142+ // Numeric
143+ [ YQLType . Bool ] : 80 ,
144+ [ YQLType . Int8 ] : 80 ,
145+ [ YQLType . Int16 ] : 90 ,
146+ [ YQLType . Int32 ] : 140 ,
147+ [ YQLType . Int64 ] : 220 ,
148+ [ YQLType . Uint8 ] : 80 ,
149+ [ YQLType . Uint16 ] : 90 ,
150+ [ YQLType . Uint32 ] : 140 ,
151+ [ YQLType . Uint64 ] : 220 ,
152+ [ YQLType . Float ] : 120 ,
153+ [ YQLType . Double ] : 220 ,
154+ [ YQLType . Decimal ] : 220 ,
155+
156+ // String
157+ [ YQLType . String ] : 240 ,
158+ [ YQLType . Utf8 ] : 240 ,
159+ [ YQLType . Json ] : 340 ,
160+ [ YQLType . JsonDocument ] : 340 ,
161+ [ YQLType . Yson ] : 340 ,
162+ [ YQLType . Uuid ] : 190 ,
163+
164+ // Date and time
165+ [ YQLType . Date ] : 300 ,
166+ [ YQLType . Datetime ] : 300 ,
167+ [ YQLType . Timestamp ] : 300 ,
168+ [ YQLType . Interval ] : 300 ,
169+ [ YQLType . TzDate ] : 300 ,
170+ [ YQLType . TzDateTime ] : 300 ,
171+ [ YQLType . TzTimestamp ] : 300 ,
172+ } ;
173+
174+ const COLUMN_DEFAULT_WIDTH = 200 ;
175+
176+ export const getColumnWidthByType = ( type : string , columnName : string ) => {
177+ const yqlType = getYQLColumnType ( type ) ;
178+
179+ return Math . max (
180+ columnTypeToDefaultWidth [ yqlType ] || COLUMN_DEFAULT_WIDTH ,
181+ columnName . length * 15 ,
182+ ) ;
183+ } ;
184+
137185/** parse response result from ArrayRow to KeyValueRow */
138186const parseModernResult = ( rows : ArrayRow [ ] , columns : ColumnType [ ] ) => {
139187 return rows . map ( ( row ) => {
0 commit comments