Search in sources :

Example 1 with SqlBuilder

use of org.apache.calcite.sql.util.SqlBuilder in project calcite by apache.

the class UtilTest method testSqlBuilder.

/**
 * Tests SQL builders.
 */
@Test
public void testSqlBuilder() {
    final SqlBuilder buf = new SqlBuilder(CalciteSqlDialect.DEFAULT);
    assertEquals(0, buf.length());
    buf.append("select ");
    assertEquals("select ", buf.getSql());
    buf.identifier("x");
    assertEquals("select \"x\"", buf.getSql());
    buf.append(", ");
    buf.identifier("y", "a b");
    assertEquals("select \"x\", \"y\".\"a b\"", buf.getSql());
    final SqlString sqlString = buf.toSqlString();
    assertEquals(CalciteSqlDialect.DEFAULT, sqlString.getDialect());
    assertEquals(buf.getSql(), sqlString.getSql());
    assertTrue(buf.getSql().length() > 0);
    assertEquals(buf.getSqlAndClear(), sqlString.getSql());
    assertEquals(0, buf.length());
    buf.clear();
    assertEquals(0, buf.length());
    buf.literal("can't get no satisfaction");
    assertEquals("'can''t get no satisfaction'", buf.getSqlAndClear());
    buf.literal(new Timestamp(0));
    assertEquals("TIMESTAMP '1970-01-01 00:00:00'", buf.getSqlAndClear());
    buf.clear();
    assertEquals(0, buf.length());
    buf.append("hello world");
    assertEquals(2, buf.indexOf("l"));
    assertEquals(-1, buf.indexOf("z"));
    assertEquals(9, buf.indexOf("l", 5));
}
Also used : SqlBuilder(org.apache.calcite.sql.util.SqlBuilder) Timestamp(java.sql.Timestamp) SqlString(org.apache.calcite.sql.util.SqlString) Test(org.junit.Test)

Example 2 with SqlBuilder

use of org.apache.calcite.sql.util.SqlBuilder in project drill by apache.

the class JdbcRecordWriter method initializeInsertQuery.

private SqlBuilder initializeInsertQuery() {
    SqlBuilder builder = new SqlBuilder(this.dialect);
    // Apache Phoenix does not support INSERT but does support UPSERT using the same syntax
    if (dialect == DatabaseProduct.PHOENIX.getDialect()) {
        builder.append("UPSERT INTO ");
    } else {
        builder.append("INSERT INTO ");
    }
    JdbcDDLQueryUtils.addTableToInsertQuery(builder, rawTableName);
    builder.append(" VALUES ");
    return builder;
}
Also used : SqlBuilder(org.apache.calcite.sql.util.SqlBuilder)

Aggregations

SqlBuilder (org.apache.calcite.sql.util.SqlBuilder)2 Timestamp (java.sql.Timestamp)1 SqlString (org.apache.calcite.sql.util.SqlString)1 Test (org.junit.Test)1