You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@phoenix.apache.org by "Ankit Singhal (JIRA)" <ji...@apache.org> on 2017/09/23 11:08:02 UTC
[jira] [Commented] (PHOENIX-4228) Schema set by "USE SCHEMA"
statement is used even when schema name is set explicitly
[ https://issues.apache.org/jira/browse/PHOENIX-4228?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16177726#comment-16177726 ]
Ankit Singhal commented on PHOENIX-4228:
----------------------------------------
I believe following code should already be taking care of this.(and same for multiTableResolver ).
FromCompiler#SingleTableColumnResolver
{code}
if (connection.getSchema() != null) {
schema = schema != null ? schema : connection.getSchema();
}
{code}
For me, the following unit test case passes. Am I missing something here?
{code}@Test
public void testSchema() throws Exception {
Properties props = new Properties();
String schema="S";
props.setProperty(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, Boolean.toString(true));
Connection conn = DriverManager.getConnection(getUrl(), props);
String ddl = "CREATE SCHEMA IF NOT EXISTS "+schema;
conn.createStatement().execute(ddl);
ddl = "CREATE SCHEMA IF NOT EXISTS "+schema+"1";
conn.createStatement().execute(ddl);
ddl = "create table "+schema+".TEST(id varchar primary key)";
conn.createStatement().execute(ddl);
conn.createStatement().execute("use "+schema+"1");
query = "select count(*) from "+schema+".TEST";
rs = conn.createStatement().executeQuery(query);
assertTrue(rs.next());
assertEquals(0, rs.getInt(1));
}
{code}
> Schema set by "USE SCHEMA" statement is used even when schema name is set explicitly
> ------------------------------------------------------------------------------------
>
> Key: PHOENIX-4228
> URL: https://issues.apache.org/jira/browse/PHOENIX-4228
> Project: Phoenix
> Issue Type: Bug
> Affects Versions: 4.12.0
> Reporter: Karan Mehta
>
> The following is the documented behavior for USE SCHEMA statement.
> {code}
> Sets a default schema for the connection and is used as a target schema for all statements issued from the connection that do not specify schema name explicitly. USE DEFAULT unset the schema for the connection so that no schema will be used for the statements issued from the connection.
> {code}
> However this behaviour is not honoured for certain statements. For example if the following SQL is executed
> {code}
> 1. USE SCHEMA SCHEMA1;
> 2. SELECT * FROM SCHEMA2.TABLE2;
> {code}
> Phoenix will try to resolve the table {{SCHEMA2.TABLE2}} to {{SCHEMA1.SCHEMA2.TABLE2}} and hence will fail, even though SCHEMA2.TABLE2 table can exist. This JIRA is to track the fix for the table name resolver.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)