Java Code Examples for org.apache.phoenix.util.SchemaUtil#getEscapedArgument()

The following examples show how to use org.apache.phoenix.util.SchemaUtil#getEscapedArgument() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PhoenixConfigurationUtilTest.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testSelectStatement() throws Exception {
    Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES));
    final String tableName = "TEST_TABLE";
    try {
        String ddl = "CREATE TABLE "+ tableName + 
                "  (a_string varchar not null, a_binary varbinary not null, col1 integer" +
                "  CONSTRAINT pk PRIMARY KEY (a_string, a_binary))\n";
        conn.createStatement().execute(ddl);
        final Configuration configuration = new Configuration ();
        configuration.set(HConstants.ZOOKEEPER_QUORUM, getUrl());
        PhoenixConfigurationUtil.setInputTableName(configuration, tableName);
        final String selectStatement = PhoenixConfigurationUtil.getSelectStatement(configuration);
        final String expectedSelectStatement = "SELECT \"A_STRING\",\"A_BINARY\",\"0\".\"COL1\" FROM " + SchemaUtil.getEscapedArgument(tableName) ; 
        assertEquals(expectedSelectStatement, selectStatement);
    } finally {
        conn.close();
    }
}
 
Example 2
Source File: PhoenixConfigurationUtilTest.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testSelectStatementForSpecificColumns() throws Exception {
    Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES));
    final String tableName = "TEST_TABLE";
    try {
        String ddl = "CREATE TABLE "+ tableName + 
                "  (a_string varchar not null, a_binary varbinary not null, col1 integer" +
                "  CONSTRAINT pk PRIMARY KEY (a_string, a_binary))\n";
        conn.createStatement().execute(ddl);
        final Configuration configuration = new Configuration ();
        configuration.set(HConstants.ZOOKEEPER_QUORUM, getUrl());
        PhoenixConfigurationUtil.setInputTableName(configuration, tableName);
        PhoenixConfigurationUtil.setSelectColumnNames(configuration, "A_BINARY");
        final String selectStatement = PhoenixConfigurationUtil.getSelectStatement(configuration);
        final String expectedSelectStatement = "SELECT \"A_BINARY\" FROM " + SchemaUtil.getEscapedArgument(tableName) ; 
        assertEquals(expectedSelectStatement, selectStatement);
    } finally {
        conn.close();
    }
}
 
Example 3
Source File: PhoenixConfigurationUtilTest.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testSelectStatementForArrayTypes() throws Exception {
    Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES));
    final String tableName = "TEST_TABLE";
    try {
        String ddl = "CREATE TABLE "+ tableName + 
                "  (ID BIGINT NOT NULL PRIMARY KEY, VCARRAY VARCHAR[])\n";
        conn.createStatement().execute(ddl);
        final Configuration configuration = new Configuration ();
        configuration.set(HConstants.ZOOKEEPER_QUORUM, getUrl());
        PhoenixConfigurationUtil.setSelectColumnNames(configuration,"ID,VCARRAY");
        PhoenixConfigurationUtil.setSchemaType(configuration, SchemaType.QUERY);
        PhoenixConfigurationUtil.setInputTableName(configuration, tableName);
        final String selectStatement = PhoenixConfigurationUtil.getSelectStatement(configuration);
        final String expectedSelectStatement = "SELECT \"ID\",\"0\".\"VCARRAY\" FROM " + SchemaUtil.getEscapedArgument(tableName) ; 
        assertEquals(expectedSelectStatement, selectStatement);
    } finally {
        conn.close();
    }
}
 
Example 4
Source File: PhoenixConfigurationUtilTest.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testSelectStatementWithSchema() throws Exception {
    Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES));
    final String tableName = "TEST_TABLE";
    final String schemaName = SchemaUtil.getEscapedArgument("schema");
    final String fullTableName = SchemaUtil.getTableName(schemaName, tableName);
    try {
        String ddl = "CREATE TABLE "+ fullTableName + 
                "  (a_string varchar not null, a_binary varbinary not null, col1 integer" +
                "  CONSTRAINT pk PRIMARY KEY (a_string, a_binary))\n";
        conn.createStatement().execute(ddl);
        final Configuration configuration = new Configuration ();
        configuration.set(HConstants.ZOOKEEPER_QUORUM, getUrl());
        PhoenixConfigurationUtil.setInputTableName(configuration, fullTableName);
        final String selectStatement = PhoenixConfigurationUtil.getSelectStatement(configuration);
        final String expectedSelectStatement = "SELECT \"A_STRING\" , \"A_BINARY\" , \"0\".\"COL1\" FROM " + fullTableName;
        assertEquals(expectedSelectStatement, selectStatement);
    } finally {
        conn.close();
    }
}