|
18 | 18 |
|
19 | 19 | import static com.google.common.base.CaseFormat.UPPER_CAMEL; |
20 | 20 | import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE; |
| 21 | +import static org.apache.hadoop.util.Preconditions.checkNotNull; |
21 | 22 |
|
22 | 23 | import com.google.common.base.CharMatcher; |
23 | 24 | import com.google.common.base.Joiner; |
@@ -85,7 +86,9 @@ public final Handle open(@Nonnull ConnectorArguments arguments) |
85 | 86 | DataSource dataSource = new SimpleDriverDataSource(newDriver(arguments), url, properties); |
86 | 87 | if (arguments.isAssessment()) { |
87 | 88 | JdbcHandle handle = new JdbcHandle(dataSource); |
88 | | - setCurrentDatabase("SNOWFLAKE", handle.getJdbcTemplate()); |
| 89 | + JdbcTemplate template = handle.getJdbcTemplate(); |
| 90 | + String actualDatabase = template.queryForObject("USE DATABASE SNOWFLAKE;", String.class); |
| 91 | + checkNotNull(actualDatabase); |
89 | 92 | return handle; |
90 | 93 | } else { |
91 | 94 | String databaseName = |
@@ -204,16 +207,16 @@ private void setCurrentDatabase(@Nonnull String databaseName, @Nonnull JdbcTempl |
204 | 207 | } |
205 | 208 |
|
206 | 209 | String sanitizeDatabaseName(@Nonnull String databaseName) throws MetadataDumperUsageException { |
207 | | - CharMatcher doubleQuoteMatcher = CharMatcher.is('"'); |
208 | | - String trimmedName = doubleQuoteMatcher.trimFrom(databaseName); |
209 | | - int charLengthWithQuotes = databaseName.length() + 2; |
210 | | - int maxDatabaseCharLength = 255; |
211 | | - if (charLengthWithQuotes > 255) { |
| 210 | + int lengthWithQuotes = databaseName.length() + 2; |
| 211 | + int maxLength = 255; |
| 212 | + if (lengthWithQuotes > maxLength) { |
212 | 213 | throw new MetadataDumperUsageException( |
213 | 214 | String.format( |
214 | 215 | "The provided database name has %d characters, which is longer than the maximum allowed number %d for Snowflake identifiers.", |
215 | | - charLengthWithQuotes, maxDatabaseCharLength)); |
| 216 | + lengthWithQuotes, maxLength)); |
216 | 217 | } |
| 218 | + CharMatcher doubleQuoteMatcher = CharMatcher.is('"'); |
| 219 | + String trimmedName = doubleQuoteMatcher.trimFrom(databaseName); |
217 | 220 | if (doubleQuoteMatcher.matchesAnyOf(trimmedName)) { |
218 | 221 | throw new MetadataDumperUsageException( |
219 | 222 | "Database name has incorrectly placed double quote(s). Aborting query."); |
|
0 commit comments