62
62
public class StarRocksCatalog implements Catalog {
63
63
64
64
protected final String catalogName ;
65
- protected final String defaultDatabase ;
65
+ protected String defaultDatabase = "default" ;
66
66
protected final String username ;
67
67
protected final String pwd ;
68
68
protected final String baseUrl ;
69
- protected final String defaultUrl ;
69
+ protected String defaultUrl ;
70
70
71
71
private static final Set <String > SYS_DATABASES = new HashSet <>();
72
72
private static final Logger LOG = LoggerFactory .getLogger (StarRocksCatalog .class );
@@ -87,14 +87,17 @@ public StarRocksCatalog(
87
87
checkArgument (StringUtils .isNotBlank (defaultUrl ));
88
88
89
89
defaultUrl = defaultUrl .trim ();
90
- validateJdbcUrlWithDatabase (defaultUrl );
90
+ if (validateJdbcUrlWithDatabase (defaultUrl )) {
91
+ String [] strings = splitDefaultUrl (defaultUrl );
92
+ this .baseUrl = strings [0 ];
93
+ this .defaultDatabase = strings [1 ];
94
+ } else {
95
+ this .baseUrl = defaultUrl ;
96
+ }
91
97
this .catalogName = catalogName ;
92
98
this .username = username ;
93
99
this .pwd = pwd ;
94
100
this .defaultUrl = defaultUrl ;
95
- String [] strings = splitDefaultUrl (defaultUrl );
96
- this .baseUrl = strings [0 ];
97
- this .defaultDatabase = strings [1 ];
98
101
}
99
102
100
103
public StarRocksCatalog (
@@ -109,13 +112,18 @@ public StarRocksCatalog(
109
112
checkArgument (StringUtils .isNotBlank (baseUrl ));
110
113
111
114
baseUrl = baseUrl .trim ();
112
- validateJdbcUrlWithoutDatabase (baseUrl );
115
+ if (validateJdbcUrlWithoutDatabase (baseUrl )) {
116
+ this .baseUrl = baseUrl .endsWith ("/" ) ? baseUrl : baseUrl + "/" ;
117
+ this .defaultUrl = this .baseUrl + defaultDatabase ;
118
+ } else {
119
+ String [] strings = splitDefaultUrl (baseUrl );
120
+ this .baseUrl = strings [0 ];
121
+ }
113
122
this .catalogName = catalogName ;
114
123
this .defaultDatabase = defaultDatabase ;
115
124
this .username = username ;
116
125
this .pwd = pwd ;
117
- this .baseUrl = baseUrl .endsWith ("/" ) ? baseUrl : baseUrl + "/" ;
118
- this .defaultUrl = this .baseUrl + defaultDatabase ;
126
+
119
127
}
120
128
121
129
@ Override
@@ -326,19 +334,19 @@ public void createTable(String sql) throws TableAlreadyExistException, DatabaseN
326
334
* URL has to be without database, like "jdbc:mysql://localhost:5432/" or
327
335
* "jdbc:mysql://localhost:5432" rather than "jdbc:mysql://localhost:5432/db".
328
336
*/
329
- public static void validateJdbcUrlWithoutDatabase (String url ) {
337
+ public static boolean validateJdbcUrlWithoutDatabase (String url ) {
330
338
String [] parts = url .trim ().split ("\\ /+" );
331
339
332
- checkArgument ( parts .length == 2 ) ;
340
+ return parts .length == 2 ;
333
341
}
334
342
335
343
/**
336
344
* URL has to be with database, like "jdbc:mysql://localhost:5432/db" rather than "jdbc:mysql://localhost:5432/".
337
345
*/
338
346
@ SuppressWarnings ("MagicNumber" )
339
- public static void validateJdbcUrlWithDatabase (String url ) {
347
+ public static boolean validateJdbcUrlWithDatabase (String url ) {
340
348
String [] parts = url .trim ().split ("\\ /+" );
341
- checkArgument ( parts .length == 3 ) ;
349
+ return parts .length == 3 ;
342
350
}
343
351
344
352
/**
0 commit comments