-
Notifications
You must be signed in to change notification settings - Fork 4.8k
HIVE-29308: Exception when JDBC table names are case-sensitive #6727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
soumyakanti3578
wants to merge
2
commits into
apache:master
Choose a base branch
from
soumyakanti3578:HIVE-29308-jdbc-case
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
data/scripts/q_test_case_sensitive_country_table.mariadb.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| -- country and `Country` are distinct tables. | ||
| CREATE SCHEMA bob; | ||
|
|
||
| CREATE TABLE bob.country | ||
| ( | ||
| id int, | ||
| name varchar(20) | ||
| ); | ||
| insert into bob.country values (1, 'India'); | ||
| insert into bob.country values (2, 'Russia'); | ||
| insert into bob.country values (3, 'USA'); | ||
|
|
||
| CREATE TABLE bob.`Country` | ||
| ( | ||
| id int, | ||
| name varchar(20) | ||
| ); | ||
| insert into bob.`Country` values (10, 'Italy'); | ||
| insert into bob.`Country` values (11, 'Greece'); | ||
|
|
||
|
|
24 changes: 24 additions & 0 deletions
24
data/scripts/q_test_case_sensitive_country_table.mssql.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| -- A case-sensitive collation makes country and [Country] distinct tables. | ||
| CREATE DATABASE worldcs COLLATE Latin1_General_CS_AS; | ||
| USE worldcs; | ||
|
|
||
| CREATE SCHEMA bob; | ||
|
|
||
| CREATE TABLE bob.country | ||
| ( | ||
| id int, | ||
| name varchar(20) | ||
| ); | ||
| insert into bob.country values (1, 'India'); | ||
| insert into bob.country values (2, 'Russia'); | ||
| insert into bob.country values (3, 'USA'); | ||
|
|
||
| CREATE TABLE bob.[Country] | ||
| ( | ||
| id int, | ||
| name varchar(20) | ||
| ); | ||
| insert into bob.[Country] values (10, 'Italy'); | ||
| insert into bob.[Country] values (11, 'Greece'); | ||
|
|
||
|
|
19 changes: 19 additions & 0 deletions
19
data/scripts/q_test_case_sensitive_country_table.mysql.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| -- country and `Country` are distinct tables. | ||
| CREATE TABLE country | ||
| ( | ||
| id int, | ||
| name varchar(20) | ||
| ); | ||
| insert into country values (1, 'India'); | ||
| insert into country values (2, 'Russia'); | ||
| insert into country values (3, 'USA'); | ||
|
|
||
| CREATE TABLE `Country` | ||
| ( | ||
| id int, | ||
| name varchar(20) | ||
| ); | ||
| insert into `Country` values (10, 'Italy'); | ||
| insert into `Country` values (11, 'Greece'); | ||
|
|
||
|
|
25 changes: 25 additions & 0 deletions
25
data/scripts/q_test_case_sensitive_country_table.oracle.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| -- country (unquoted, folded to COUNTRY) and "Country" (quoted, case-sensitive) are distinct tables. | ||
| ALTER SESSION SET CONTAINER = XEPDB1; | ||
|
|
||
| CREATE USER bob IDENTIFIED BY bobpass; | ||
| ALTER USER bob QUOTA UNLIMITED ON users; | ||
| GRANT CREATE SESSION TO bob; | ||
|
|
||
| CREATE TABLE bob.country | ||
| ( | ||
| id int, | ||
| name varchar(20) | ||
| ); | ||
| insert into bob.country values (1, 'India'); | ||
| insert into bob.country values (2, 'Russia'); | ||
| insert into bob.country values (3, 'USA'); | ||
|
|
||
| CREATE TABLE bob."Country" | ||
| ( | ||
| id int, | ||
| name varchar(20) | ||
| ); | ||
| insert into bob."Country" values (10, 'Italy'); | ||
| insert into bob."Country" values (11, 'Greece'); | ||
|
|
||
|
|
21 changes: 21 additions & 0 deletions
21
data/scripts/q_test_case_sensitive_country_table.postgres.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| -- country (unquoted, lowercase) and "Country" (quoted, case-sensitive) are distinct tables. | ||
| CREATE SCHEMA bob; | ||
|
|
||
| CREATE TABLE bob.country | ||
| ( | ||
| id int, | ||
| name varchar(20) | ||
| ); | ||
| insert into bob.country values (1, 'India'); | ||
| insert into bob.country values (2, 'Russia'); | ||
| insert into bob.country values (3, 'USA'); | ||
|
|
||
| CREATE TABLE bob."Country" | ||
| ( | ||
| id int, | ||
| name varchar(20) | ||
| ); | ||
| insert into bob."Country" values (10, 'Italy'); | ||
| insert into bob."Country" values (11, 'Greece'); | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
jdbc-handler/src/test/java/org/apache/hive/storage/jdbc/TestJdbcStorageHandlerAuthUri.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.hive.storage.jdbc; | ||
|
|
||
| import org.apache.hadoop.hive.metastore.api.SerDeInfo; | ||
| import org.apache.hadoop.hive.metastore.api.StorageDescriptor; | ||
| import org.apache.hadoop.hive.metastore.api.Table; | ||
| import org.junit.Test; | ||
|
|
||
| import java.net.URI; | ||
| import java.net.URISyntaxException; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
|
|
||
| /** | ||
| * Unit tests for {@link JdbcStorageHandler#getURIForAuth(Table)}. | ||
| */ | ||
| public class TestJdbcStorageHandlerAuthUri { | ||
|
|
||
| private static Table tableWith(Map<String, String> params) { | ||
| Table table = new Table(); | ||
| table.setParameters(params); | ||
| StorageDescriptor sd = new StorageDescriptor(); | ||
| sd.setSerdeInfo(new SerDeInfo("serde", "serde.lib", new HashMap<>())); | ||
| table.setSd(sd); | ||
| return table; | ||
| } | ||
|
|
||
| private URI authUri(String jdbcUrl, String schema, String table) throws URISyntaxException { | ||
| Map<String, String> params = new HashMap<>(); | ||
| params.put("hive.sql.database.type", "POSTGRES"); | ||
| params.put("hive.sql.jdbc.url", jdbcUrl); | ||
| if (schema != null) { | ||
| params.put("hive.sql.schema", schema); | ||
| } | ||
| if (table != null) { | ||
| params.put("hive.sql.table", table); | ||
| } | ||
| return new JdbcStorageHandler().getURIForAuth(tableWith(params)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testUnquotedTableUnchanged() throws Exception { | ||
| URI uri = authUri("jdbc:postgresql://host:5432/db", null, "country"); | ||
| assertEquals("jdbc:postgresql://host:5432/db/country", uri.toString()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testQuotedTableStripsQuotesPreservingCase() throws Exception { | ||
| URI uri = authUri("jdbc:postgresql://host:5432/db", null, "\"Country\""); | ||
| // The physical identifier keeps its original case, and the surrounding quotes are stripped. | ||
| assertEquals("jdbc:postgresql://host:5432/db/Country", uri.toString()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testQuotedTableWithSchemaOnlyEncodesTable() throws Exception { | ||
| URI uri = authUri("jdbc:postgresql://host:5432/db", "\"World\"", "\"Country\""); | ||
| assertEquals("jdbc:postgresql://host:5432/db/Country", uri.toString()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testMissingTablePropertyFailsFast() { | ||
| try { | ||
| authUri("jdbc:postgresql://host:5432/db", null, null); | ||
| org.junit.Assert.fail("Expected URISyntaxException"); | ||
| } catch (URISyntaxException e) { | ||
| assertEquals("Missing required table property: hive.sql.table", e.getReason()); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testTableWithSpecialCharactersIsUriSafe() throws Exception { | ||
| // A quoted identifier may legally contain characters that are illegal in a raw URI; they must be encoded. | ||
| URI uri = authUri("jdbc:postgresql://host:5432/db", null, "\"Odd/Name\""); | ||
| // '/' -> %2F ; the resulting string is a valid URI. | ||
| assertEquals("jdbc:postgresql://host:5432/db/Odd%2FName", uri.toString()); | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the JDBC URL contain the schema? I've found a Stackoverflow question. There is a param
currentSchemafor Postgres JDBC, and search_path (or searchpath?) for non-JDBC URLs.Changing the URL for this case might be out-of-scope for HIVE-29308.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this seems out of scope for this PR, but this can be done in a follow up.