Search in sources :

Example 1 with PhoenixSchemaStatVisitor

use of com.alibaba.druid.sql.dialect.phoenix.visitor.PhoenixSchemaStatVisitor in project druid by alibaba.

the class PhoenixUpsertTest method test_0.

public void test_0() throws Exception {
    String sql = "upsert into t_1 (a,b,c) values (?,?,?)";
    List<SQLStatement> statementList = SQLUtils.parseStatements(sql, JdbcConstants.PHOENIX);
    SQLStatement stmt = statementList.get(0);
    Assert.assertEquals(1, statementList.size());
    SchemaStatVisitor visitor = new PhoenixSchemaStatVisitor();
    stmt.accept(visitor);
    //        System.out.println("Tables : " + visitor.getTables());
    //        System.out.println("fields : " + visitor.getColumns());
    //        System.out.println("coditions : " + visitor.getConditions());
    //        System.out.println("orderBy : " + visitor.getOrderByColumns());
    Assert.assertEquals(1, visitor.getTables().size());
    Assert.assertEquals(3, visitor.getColumns().size());
    Assert.assertEquals(0, visitor.getConditions().size());
    Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("t_1")));
    Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("t_1", "a")));
    Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("t_1", "b")));
    Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("t_1", "c")));
    // Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "first_name")));
    // Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "full_name")));
    String output = SQLUtils.toSQLString(stmt, JdbcConstants.PHOENIX);
    Assert.assertEquals("UPSERT INTO t_1 (a, b, c)\n" + //
    "VALUES (?, ?, ?)", output);
}
Also used : PhoenixSchemaStatVisitor(com.alibaba.druid.sql.dialect.phoenix.visitor.PhoenixSchemaStatVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) DB2SchemaStatVisitor(com.alibaba.druid.sql.dialect.db2.visitor.DB2SchemaStatVisitor) SchemaStatVisitor(com.alibaba.druid.sql.visitor.SchemaStatVisitor) PhoenixSchemaStatVisitor(com.alibaba.druid.sql.dialect.phoenix.visitor.PhoenixSchemaStatVisitor)

Example 2 with PhoenixSchemaStatVisitor

use of com.alibaba.druid.sql.dialect.phoenix.visitor.PhoenixSchemaStatVisitor in project druid by alibaba.

the class PhoenixUpsertTest_1 method test_0.

public void test_0() throws Exception {
    String sql = "upsert into t_1 (a BIGINT,b,c) values (?,?,?)";
    List<SQLStatement> statementList = SQLUtils.parseStatements(sql, JdbcConstants.PHOENIX);
    SQLStatement stmt = statementList.get(0);
    Assert.assertEquals(1, statementList.size());
    SchemaStatVisitor visitor = new PhoenixSchemaStatVisitor();
    stmt.accept(visitor);
    //        System.out.println("Tables : " + visitor.getTables());
    //        System.out.println("fields : " + visitor.getColumns());
    //        System.out.println("coditions : " + visitor.getConditions());
    //        System.out.println("orderBy : " + visitor.getOrderByColumns());
    Assert.assertEquals(1, visitor.getTables().size());
    Assert.assertEquals(3, visitor.getColumns().size());
    Assert.assertEquals(0, visitor.getConditions().size());
    Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("t_1")));
    Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("t_1", "a")));
    Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("t_1", "b")));
    Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("t_1", "c")));
    // Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "first_name")));
    // Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "full_name")));
    String output = SQLUtils.toSQLString(stmt, JdbcConstants.PHOENIX);
    Assert.assertEquals("UPSERT INTO t_1 (a BIGINT, b, c)\n" + //
    "VALUES (?, ?, ?)", output);
}
Also used : PhoenixSchemaStatVisitor(com.alibaba.druid.sql.dialect.phoenix.visitor.PhoenixSchemaStatVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) SchemaStatVisitor(com.alibaba.druid.sql.visitor.SchemaStatVisitor) PhoenixSchemaStatVisitor(com.alibaba.druid.sql.dialect.phoenix.visitor.PhoenixSchemaStatVisitor)

Example 3 with PhoenixSchemaStatVisitor

use of com.alibaba.druid.sql.dialect.phoenix.visitor.PhoenixSchemaStatVisitor in project druid by alibaba.

the class PhoenixUpsertTest_2 method test_0.

public void test_0() throws Exception {
    String sql = "upsert into t_1 (a CHAR(15),b,c) values (?,?,?)";
    List<SQLStatement> statementList = SQLUtils.parseStatements(sql, JdbcConstants.PHOENIX);
    SQLStatement stmt = statementList.get(0);
    Assert.assertEquals(1, statementList.size());
    SchemaStatVisitor visitor = new PhoenixSchemaStatVisitor();
    stmt.accept(visitor);
    //        System.out.println("Tables : " + visitor.getTables());
    //        System.out.println("fields : " + visitor.getColumns());
    //        System.out.println("coditions : " + visitor.getConditions());
    //        System.out.println("orderBy : " + visitor.getOrderByColumns());
    Assert.assertEquals(1, visitor.getTables().size());
    Assert.assertEquals(3, visitor.getColumns().size());
    Assert.assertEquals(0, visitor.getConditions().size());
    Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("t_1")));
    Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("t_1", "a")));
    Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("t_1", "b")));
    Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("t_1", "c")));
    // Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "first_name")));
    // Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "full_name")));
    String output = SQLUtils.toSQLString(stmt, JdbcConstants.PHOENIX);
    Assert.assertEquals("UPSERT INTO t_1 (a CHAR(15), b, c)\n" + //
    "VALUES (?, ?, ?)", output);
}
Also used : PhoenixSchemaStatVisitor(com.alibaba.druid.sql.dialect.phoenix.visitor.PhoenixSchemaStatVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) SchemaStatVisitor(com.alibaba.druid.sql.visitor.SchemaStatVisitor) PhoenixSchemaStatVisitor(com.alibaba.druid.sql.dialect.phoenix.visitor.PhoenixSchemaStatVisitor)

Example 4 with PhoenixSchemaStatVisitor

use of com.alibaba.druid.sql.dialect.phoenix.visitor.PhoenixSchemaStatVisitor in project druid by alibaba.

the class PhoenixUpsertTest_std method test_0.

public void test_0() throws Exception {
    String sql = "upsert into t_1 (a,b,c) values (?,?,?)";
    List<SQLStatement> statementList = SQLUtils.parseStatements(sql, null);
    SQLStatement stmt = statementList.get(0);
    Assert.assertEquals(1, statementList.size());
    SchemaStatVisitor visitor = new PhoenixSchemaStatVisitor();
    stmt.accept(visitor);
    //        System.out.println("Tables : " + visitor.getTables());
    //        System.out.println("fields : " + visitor.getColumns());
    //        System.out.println("coditions : " + visitor.getConditions());
    //        System.out.println("orderBy : " + visitor.getOrderByColumns());
    Assert.assertEquals(1, visitor.getTables().size());
    Assert.assertEquals(3, visitor.getColumns().size());
    Assert.assertEquals(0, visitor.getConditions().size());
    Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("t_1")));
    Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("t_1", "a")));
    Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("t_1", "b")));
    Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("t_1", "c")));
    // Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "first_name")));
    // Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "full_name")));
    String output = SQLUtils.toSQLString(stmt, JdbcConstants.PHOENIX);
    Assert.assertEquals("UPSERT INTO t_1 (a, b, c)\n" + //
    "VALUES (?, ?, ?)", output);
}
Also used : PhoenixSchemaStatVisitor(com.alibaba.druid.sql.dialect.phoenix.visitor.PhoenixSchemaStatVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) SchemaStatVisitor(com.alibaba.druid.sql.visitor.SchemaStatVisitor) PhoenixSchemaStatVisitor(com.alibaba.druid.sql.dialect.phoenix.visitor.PhoenixSchemaStatVisitor)

Aggregations

SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)4 PhoenixSchemaStatVisitor (com.alibaba.druid.sql.dialect.phoenix.visitor.PhoenixSchemaStatVisitor)4 SchemaStatVisitor (com.alibaba.druid.sql.visitor.SchemaStatVisitor)4 DB2SchemaStatVisitor (com.alibaba.druid.sql.dialect.db2.visitor.DB2SchemaStatVisitor)1