You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@phoenix.apache.org by "Daniel Wong (JIRA)" <ji...@apache.org> on 2019/01/09 23:22:00 UTC

[jira] [Commented] (PHOENIX-5093) Schema and Table with leading underscore '_' cannot be queried though grammar says it is valid.

    [ https://issues.apache.org/jira/browse/PHOENIX-5093?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16738769#comment-16738769 ] 

Daniel Wong commented on PHOENIX-5093:
--------------------------------------

{code:java}
public class QueryTableNameIT extends ParallelStatsDisabledIT {

 Connection conn = null;


 String schemaName = "_UNDERSCORE_LED_SCHEMA_NAME";
 String tableName = "_UNDERSCORE_LED_TABLE_NAME";
 String qualifiedName = schemaName + "." + tableName;

 @Before
 public void setup(){
 Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
 props.setProperty(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, Boolean.toString(true));
 try {
 conn = DriverManager.getConnection(getUrl(), props);
 Statement statement = conn.createStatement();
 String createSchema = "CREATE SCHEMA IF NOT EXISTS " + schemaName;

 String createTable = "CREATE TABLE IF NOT EXISTS " + qualifiedName + " (KEY INTEGER NOT NULL PRIMARY KEY, VAL VARCHAR)";

 statement.execute(createSchema);
 statement.execute(createTable);

 conn.commit();

 statement.close();

 } catch (Exception e){
 throw new RuntimeException(e);
 }
 }

 @After
 public void tearDown(){
 if(conn != null){
 try {
 conn.close();
 } catch(Exception e){
 throw new RuntimeException(e);
 }
 }
 }

 /**
 * See https://phoenix.apache.org/language/index.html#name
 */

 @Test
 public void testQuerySchemaTableName() throws Exception { // TODO: test more conversion combinations

 try {
 Statement statement = conn.createStatement();
 String query = "SELECT count(*) from " + qualifiedName;

 ResultSet rs = statement.executeQuery(query);

 assertTrue(rs.next());


 //"SELECT count(*) from " + "\"" + schemaName + "\"" + "." + tableName;



 } finally {
 conn.close();
 }
 }

 @Test
 public void testQuerySchemaQuotesTableName() throws Exception { // TODO: test more conversion combinations

 try {
 Statement statement = conn.createStatement();
 String query = "SELECT count(*) from " + "\"" + schemaName + "\"" + "." + tableName;

 ResultSet rs = statement.executeQuery(query);

 assertTrue(rs.next());

 } finally {
 conn.close();
 }
 }

 @Test
 public void testQuerySchemaTableQuotesName() throws Exception { // TODO: test more conversion combinations

 try {
 Statement statement = conn.createStatement();
 String query = "SELECT count(*) from " + schemaName + "." + "\"" + tableName + "\"";

 ResultSet rs = statement.executeQuery(query);

 assertTrue(rs.next());

 } finally {
 conn.close();
 }
 }

 @Test
 public void testQuerySchemaQuotesTableQuotesName() throws Exception { // TODO: test more conversion combinations

 try {
 Statement statement = conn.createStatement();
 String query = "SELECT count(*) from " + "\"" + schemaName + "\"" + "." + "\"" + tableName + "\"";

 ResultSet rs = statement.executeQuery(query);

 assertTrue(rs.next());

 } finally {
 conn.close();
 }
 }
}{code}

> Schema and Table with leading underscore '_' cannot be queried though grammar says it is valid.
> -----------------------------------------------------------------------------------------------
>
>                 Key: PHOENIX-5093
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-5093
>             Project: Phoenix
>          Issue Type: Bug
>            Reporter: Daniel Wong
>            Priority: Minor
>
> See below for failing IT written by me.  Encountered locally while debugging issues on our clusters.  Should work according to grammar here: https://phoenix.apache.org/language/index.html#name
> May be a good newbie case.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)