You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@phoenix.apache.org by karanmehta93 <gi...@git.apache.org> on 2017/12/01 01:26:24 UTC
[GitHub] phoenix pull request #284: PHOENIX-4424 Allow users to create DEFAULT and HB...
GitHub user karanmehta93 opened a pull request:
https://github.com/apache/phoenix/pull/284
PHOENIX-4424 Allow users to create DEFAULT and HBASE Schema (Uppercas…
…e Schema Names)
@twdsilva Please review.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/karanmehta93/phoenix PHOENIX-4424
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/phoenix/pull/284.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #284
----
commit 1d745db801591ac1ca561ce3bc4b3b3f50dd2a8d
Author: Karan Mehta <ka...@gmail.com>
Date: 2017-12-01T01:25:20Z
PHOENIX-4424 Allow users to create DEFAULT and HBASE Schema (Uppercase Schema Names)
----
---
[GitHub] phoenix pull request #284: PHOENIX-4424 Allow users to create DEFAULT and HB...
Posted by karanmehta93 <gi...@git.apache.org>.
Github user karanmehta93 commented on a diff in the pull request:
https://github.com/apache/phoenix/pull/284#discussion_r154406035
--- Diff: phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java ---
@@ -4125,7 +4125,7 @@ public MutationState createSchema(CreateSchemaStatement create) throws SQLExcept
private void validateSchema(String schemaName) throws SQLException {
if (SchemaUtil.NOT_ALLOWED_SCHEMA_LIST.contains(
- schemaName.toUpperCase())) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.SCHEMA_NOT_ALLOWED)
--- End diff --
@ankitsinghal
You are correct, the schema gets normalized when we try to create a `PSchema` object and we use `PSchema.getSchemaName()` method which returns the correct schema name. Thanks for pointing it out.
However, the issue is that the normalization doesn't happen before checking the validity of the schema. As of now, the schema is uppercased even before checking if its without quotes or with quotes. This leads to issue when you try to create schema with the names DEFAULT or HBASE, which is the focus for this JIRA.
I will update the patch accordingly.
---
[GitHub] phoenix pull request #284: PHOENIX-4424 Allow users to create DEFAULT and HB...
Posted by JamesRTaylor <gi...@git.apache.org>.
Github user JamesRTaylor commented on a diff in the pull request:
https://github.com/apache/phoenix/pull/284#discussion_r154276255
--- Diff: phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java ---
@@ -4125,7 +4125,7 @@ public MutationState createSchema(CreateSchemaStatement create) throws SQLExcept
private void validateSchema(String schemaName) throws SQLException {
if (SchemaUtil.NOT_ALLOWED_SCHEMA_LIST.contains(
- schemaName.toUpperCase())) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.SCHEMA_NOT_ALLOWED)
--- End diff --
Ah, I see. Good catch. Your change is the right one.
---
[GitHub] phoenix pull request #284: PHOENIX-4424 Allow users to create DEFAULT and HB...
Posted by ankitsinghal <gi...@git.apache.org>.
Github user ankitsinghal commented on a diff in the pull request:
https://github.com/apache/phoenix/pull/284#discussion_r154282569
--- Diff: phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java ---
@@ -4125,7 +4125,7 @@ public MutationState createSchema(CreateSchemaStatement create) throws SQLExcept
private void validateSchema(String schemaName) throws SQLException {
if (SchemaUtil.NOT_ALLOWED_SCHEMA_LIST.contains(
- schemaName.toUpperCase())) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.SCHEMA_NOT_ALLOWED)
--- End diff --
@karanmehta93 , I tried case-sensitive schemas with master code, I don't see any problem. can you check if normalization is happening at some other(or not at the right) place?
```
0: jdbc:phoenix:localhost> create schema "ABC";
No rows affected (0.224 seconds)
```
```
0: jdbc:phoenix:localhost> select TABLE_SCHEM from system.catalog;
+--------------+
| TABLE_SCHEM |
+--------------+
| ABC |
```
```
hbase(main):002:0> list_namespace
NAMESPACE
ABC
```
```
0: jdbc:phoenix:localhost> create schema "small_case"
. . . . . . . . . . . . .> ;
No rows affected (0.424 seconds)
0: jdbc:phoenix:localhost> select TABLE_SCHEM from system.catalog;
+--------------+
| TABLE_SCHEM |
+--------------+
| small_case |
hbase(main):003:0> list_namespace
NAMESPACE
small_case
```
---
[GitHub] phoenix pull request #284: PHOENIX-4424 Allow users to create DEFAULT and HB...
Posted by karanmehta93 <gi...@git.apache.org>.
Github user karanmehta93 commented on a diff in the pull request:
https://github.com/apache/phoenix/pull/284#discussion_r154275774
--- Diff: phoenix-core/src/main/java/org/apache/phoenix/parse/CreateSchemaStatement.java ---
@@ -24,7 +24,7 @@
private final boolean ifNotExists;
public CreateSchemaStatement(String schemaName,boolean ifNotExists) {
- this.schemaName = null == schemaName ? SchemaUtil.SCHEMA_FOR_DEFAULT_NAMESPACE : schemaName;
+ this.schemaName = SchemaUtil.normalizeIdentifier(schemaName);
--- End diff --
@JamesRTaylor from JIRA comment
> Identifiers are case sensitive when they are double quoted in Phoenix (and SQL in general). Otherwise they are uppercased. We shouldn’t/can’t change that.
This code change will now make it adhere to SQL standards. The `SchemaUtil.normalizeIdentifier` will help handle the case sensitivity. Otherwise with the current code, if a schema name is passed with double quotes, the full name will be taken as it is for creating the schema, which is incorrect.
Also look for comments in `MetaDataClient` as well.
---
[GitHub] phoenix pull request #284: PHOENIX-4424 Allow users to create DEFAULT and HB...
Posted by karanmehta93 <gi...@git.apache.org>.
Github user karanmehta93 commented on a diff in the pull request:
https://github.com/apache/phoenix/pull/284#discussion_r154276336
--- Diff: phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java ---
@@ -4125,7 +4125,7 @@ public MutationState createSchema(CreateSchemaStatement create) throws SQLExcept
private void validateSchema(String schemaName) throws SQLException {
if (SchemaUtil.NOT_ALLOWED_SCHEMA_LIST.contains(
- schemaName.toUpperCase())) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.SCHEMA_NOT_ALLOWED)
--- End diff --
Also checkout the test I updated in `CreateSchemaIT` class.
---
[GitHub] phoenix pull request #284: PHOENIX-4424 Allow users to create DEFAULT and HB...
Posted by karanmehta93 <gi...@git.apache.org>.
Github user karanmehta93 commented on a diff in the pull request:
https://github.com/apache/phoenix/pull/284#discussion_r154737748
--- Diff: phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java ---
@@ -4125,7 +4125,7 @@ public MutationState createSchema(CreateSchemaStatement create) throws SQLExcept
private void validateSchema(String schemaName) throws SQLException {
if (SchemaUtil.NOT_ALLOWED_SCHEMA_LIST.contains(
- schemaName.toUpperCase())) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.SCHEMA_NOT_ALLOWED)
--- End diff --
@ankitsinghal Thanks for your comments. Please checkout v2 of the patch. I have fixed the bug and I updated the test to verify those scenarios. I also made sure that we don't normalize schema names multiple times, else schema names will always be in capital letters.
FYI. @twdsilva
---
[GitHub] phoenix pull request #284: PHOENIX-4424 Allow users to create DEFAULT and HB...
Posted by karanmehta93 <gi...@git.apache.org>.
Github user karanmehta93 commented on a diff in the pull request:
https://github.com/apache/phoenix/pull/284#discussion_r154276127
--- Diff: phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java ---
@@ -4125,7 +4125,7 @@ public MutationState createSchema(CreateSchemaStatement create) throws SQLExcept
private void validateSchema(String schemaName) throws SQLException {
if (SchemaUtil.NOT_ALLOWED_SCHEMA_LIST.contains(
- schemaName.toUpperCase())) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.SCHEMA_NOT_ALLOWED)
--- End diff --
This code would automatically uppercase the schema irrespective of considering if it's enclosed in quotes or not. It will use that value to validate the schema. However, will creating, it will use the regular name. Checkout Line 4093. This seems an inconsistent logic to me.
For the query
`CREATE SCHEMA "ABC"`, this code will create to create a schema with name `"ABC"` with the double quotes. There was no test that was actually testing this and thus it wasn't caught yet. I wrote a test in `QueryParserTest` and caught it.
@JamesRTaylor Please advice.
---
[GitHub] phoenix pull request #284: PHOENIX-4424 Allow users to create DEFAULT and HB...
Posted by karanmehta93 <gi...@git.apache.org>.
Github user karanmehta93 closed the pull request at:
https://github.com/apache/phoenix/pull/284
---