Exemplo n.º 1
0
  @Test
  public void testMultipleCommands2() throws Exception {
    String ddl =
        "             CREATE VIRTUAL PROCEDURE getTweets(query varchar) RETURNS (created_on varchar(25), from_user varchar(25), to_user varchar(25), \n"
            + "                 profile_image_url varchar(25), source varchar(25), text varchar(140)) AS \n"
            + "                select tweet.* from \n"
            + "	                (call twitter.invokeHTTP(action => 'GET', endpoint =>querystring('',query as \"q\"))) w, \n"
            + "	                XMLTABLE('results' passing JSONTOXML('myxml', w.result) columns \n"
            + "	                created_on string PATH 'created_at', \n"
            + "	                from_user string PATH 'from_user',\n"
            + "	                to_user string PATH 'to_user',	\n"
            + "	                profile_image_url string PATH 'profile_image_url',	\n"
            + "	                source string PATH 'source',	\n"
            + "	                text string PATH 'text') tweet;"
            + "                CREATE VIEW Tweet AS select * FROM twitterview.getTweets;";

    Schema s = helpParse(ddl, "model").getSchema();
    Map<String, Table> tableMap = s.getTables();
    Table table = tableMap.get("Tweet");
    assertNotNull(table);

    Map<String, Procedure> procedureMap = s.getProcedures();
    Procedure p = procedureMap.get("getTweets");
    assertNotNull(p);
  }
Exemplo n.º 2
0
  @Test
  public void testUDF() throws Exception {
    String ddl =
        "CREATE VIRTUAL FUNCTION SourceFunc(flag boolean, msg varchar) RETURNS varchar "
            + "OPTIONS(CATEGORY 'misc', DETERMINISM 'DETERMINISTIC', "
            + "\"NULL-ON-NULL\" 'true', JAVA_CLASS 'foo', JAVA_METHOD 'bar', RANDOM 'any', UUID 'x')";

    Schema s = helpParse(ddl, "model").getSchema();

    FunctionMethod fm = s.getFunction("x");
    assertNotNull(fm);
    assertEquals("string", fm.getOutputParameter().getType());
    assertEquals(FunctionMethod.PushDown.CAN_PUSHDOWN, fm.getPushdown());
    assertEquals(2, fm.getInputParameterCount());
    assertEquals("flag", fm.getInputParameters().get(0).getName());
    assertEquals("boolean", fm.getInputParameters().get(0).getType());
    assertEquals("msg", fm.getInputParameters().get(1).getName());
    assertEquals("string", fm.getInputParameters().get(1).getType());
    assertFalse(fm.getInputParameters().get(1).isVarArg());

    assertEquals(FunctionMethod.Determinism.DETERMINISTIC, fm.getDeterminism());
    assertEquals("misc", fm.getCategory());
    assertEquals(true, fm.isNullOnNull());
    assertEquals("foo", fm.getInvocationClass());
    assertEquals("bar", fm.getInvocationMethod());
    assertEquals("any", fm.getProperties().get("RANDOM"));
  }
Exemplo n.º 3
0
  @Test
  public void testGlobalTemp() throws Exception {
    String ddl = "CREATE GLOBAL TEMPORARY TABLE T (col string);";

    Schema s = helpParse(ddl, "model").getSchema();
    Table t = s.getTable("T");
    assertEquals(1, t.getColumns().size());
  }
Exemplo n.º 4
0
  @Test(expected = MetadataException.class)
  public void testInvalidProcedureBody() throws Exception {
    String ddl = "CREATE FOREIGN PROCEDURE SourceFunc(flag boolean) RETURNS varchar AS SELECT 'a';";

    Schema s = helpParse(ddl, "model").getSchema();

    FunctionMethod fm = s.getFunction("z");
    assertTrue(fm.getInputParameters().get(0).isVarArg());
  }
Exemplo n.º 5
0
  @Test
  public void testMixedCaseTypes() throws Exception {
    String ddl = "CREATE FUNCTION SourceFunc(flag Boolean) RETURNS varchaR options (UUID 'z')";

    Schema s = helpParse(ddl, "model").getSchema();

    FunctionMethod fm = s.getFunction("z");
    assertEquals("boolean", fm.getInputParameters().get(0).getType());
  }
Exemplo n.º 6
0
  @Test
  public void testVarArgs() throws Exception {
    String ddl =
        "CREATE FUNCTION SourceFunc(flag boolean) RETURNS varchar options (varargs 'true', UUID 'z')";

    Schema s = helpParse(ddl, "model").getSchema();

    FunctionMethod fm = s.getFunction("z");
    assertTrue(fm.getInputParameters().get(0).isVarArg());
  }
Exemplo n.º 7
0
  @Test
  public void testArrayType() throws Exception {
    String ddl = "CREATE VIEW V (col string[]) as select ('a','b');";

    Schema s = helpParse(ddl, "model").getSchema();
    Table t = s.getTable("V");
    assertEquals(1, t.getColumns().size());
    assertEquals("string[]", t.getColumns().get(0).getRuntimeType());
    assertEquals(String[].class, t.getColumns().get(0).getJavaType());
  }
Exemplo n.º 8
0
  @Test
  public void testPushdownFunctionNoArgs() throws Exception {
    String ddl =
        "CREATE FOREIGN FUNCTION SourceFunc() RETURNS integer OPTIONS (UUID 'hello world')";

    Schema s = helpParse(ddl, "model").getSchema();

    FunctionMethod fm = s.getFunction("hello world");
    assertNotNull(fm);
    assertEquals("integer", fm.getOutputParameter().getType());
    assertEquals(FunctionMethod.PushDown.MUST_PUSHDOWN, fm.getPushdown());
  }
Exemplo n.º 9
0
  @Test
  public void testOptionsKey() throws Exception {
    String ddl =
        "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar, e3 date, UNIQUE (e1) OPTIONS (CUSTOM_PROP 'VALUE'))";
    Schema s = helpParse(ddl, "model").getSchema();
    Map<String, Table> tableMap = s.getTables();

    assertTrue("Table not found", tableMap.containsKey("G1"));
    Table table = tableMap.get("G1");
    KeyRecord record = table.getAllKeys().iterator().next();
    assertEquals("VALUE", record.getProperty("CUSTOM_PROP", false));
  }
Exemplo n.º 10
0
  @Test
  public void testMultiKeyPK() throws Exception {
    String ddl = "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar, e3 date, PRIMARY KEY (e1, e2))";

    Schema s = helpParse(ddl, "model").getSchema();
    Map<String, Table> tableMap = s.getTables();

    assertTrue("Table not found", tableMap.containsKey("G1"));
    Table table = tableMap.get("G1");

    assertEquals(table.getColumns().subList(0, 2), table.getPrimaryKey().getColumns());
  }
Exemplo n.º 11
0
  @Test
  public void testFBI() throws Exception {
    String ddl =
        "CREATE FOREIGN TABLE G1(e1 integer, e2 varchar, CONSTRAINT fbi INDEX (UPPER(e2)))";

    Schema s = helpParse(ddl, "model").getSchema();
    Map<String, Table> tableMap = s.getTables();

    Table table = tableMap.get("G1");

    assertEquals(1, table.getFunctionBasedIndexes().size());
  }
Exemplo n.º 12
0
  @Test
  public void testView() throws Exception {
    String ddl =
        "CREATE View G1( e1 integer, e2 varchar) OPTIONS (CARDINALITY 12) AS select e1, e2 from foo.bar";

    Schema s = helpParse(ddl, "model").getSchema();
    Map<String, Table> tableMap = s.getTables();

    Table table = tableMap.get("G1");

    assertEquals("SELECT e1, e2 FROM foo.bar", table.getSelectTransformation());
    assertEquals(12, table.getCardinality());
  }
Exemplo n.º 13
0
  @Test
  public void sameAs() {
    // We have to assume that two schemas are always the same, regardless of name,
    // otherwise unless the reference schema has the same name as the target database
    // all the comparisons will fail - and users can choose to install databases with any schema
    // name they choose.
    assertTrue("Schemas should be considered the same", left.sameAs(right));

    // Things are always the same as themselves.
    assertTrue("Schemas are the same physical object", left.sameAs(left));

    assertFalse("A table is not the same as a schema", left.sameAs(new Table("left_schema")));
    assertFalse("null is not the same as a schema", left.sameAs(null));
  }
Exemplo n.º 14
0
  @Test
  public void testAlterTableDropOptions() throws Exception {
    String ddl =
        "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar, e3 date) OPTIONS(CARDINALITY 12, FOO 'BAR');"
            + "ALTER FOREIGN TABLE G1 OPTIONS(DROP CARDINALITY);"
            + "ALTER FOREIGN TABLE G1 OPTIONS(DROP FOO);";

    Schema s = helpParse(ddl, "model").getSchema();
    Map<String, Table> tableMap = s.getTables();

    assertTrue("Table not found", tableMap.containsKey("G1"));
    Table table = tableMap.get("G1");
    assertEquals(-1, table.getCardinality());
    assertNull(table.getProperty("FOO", false));
  }
Exemplo n.º 15
0
  @Test
  public final void testComparatorsFromJoinQual() {
    Schema outerSchema = new Schema();
    outerSchema.addColumn("employee.id1", CatalogUtil.newSimpleDataType(Type.INT4));
    outerSchema.addColumn("employee.id2", CatalogUtil.newSimpleDataType(Type.INT4));
    Schema innerSchema = new Schema();
    innerSchema.addColumn("people.fid1", CatalogUtil.newSimpleDataType(Type.INT4));
    innerSchema.addColumn("people.fid2", CatalogUtil.newSimpleDataType(Type.INT4));

    FieldEval f1 = new FieldEval("employee.id1", CatalogUtil.newSimpleDataType(Type.INT4));
    FieldEval f2 = new FieldEval("people.fid1", CatalogUtil.newSimpleDataType(Type.INT4));
    FieldEval f3 = new FieldEval("employee.id2", CatalogUtil.newSimpleDataType(Type.INT4));
    FieldEval f4 = new FieldEval("people.fid2", CatalogUtil.newSimpleDataType(Type.INT4));

    EvalNode joinQual = new BinaryEval(EvalType.EQUAL, f1, f2);
    TupleComparator[] comparators =
        PlannerUtil.getComparatorsFromJoinQual(joinQual, outerSchema, innerSchema);

    Tuple t1 = new VTuple(2);
    t1.put(0, DatumFactory.createInt4(1));
    t1.put(1, DatumFactory.createInt4(2));

    Tuple t2 = new VTuple(2);
    t2.put(0, DatumFactory.createInt4(2));
    t2.put(1, DatumFactory.createInt4(3));

    TupleComparator outerComparator = comparators[0];
    assertTrue(outerComparator.compare(t1, t2) < 0);
    assertTrue(outerComparator.compare(t2, t1) > 0);

    TupleComparator innerComparator = comparators[1];
    assertTrue(innerComparator.compare(t1, t2) < 0);
    assertTrue(innerComparator.compare(t2, t1) > 0);

    // tests for composited join key
    EvalNode joinQual2 = new BinaryEval(EvalType.EQUAL, f3, f4);
    EvalNode compositedJoinQual = new BinaryEval(EvalType.AND, joinQual, joinQual2);
    comparators =
        PlannerUtil.getComparatorsFromJoinQual(compositedJoinQual, outerSchema, innerSchema);

    outerComparator = comparators[0];
    assertTrue(outerComparator.compare(t1, t2) < 0);
    assertTrue(outerComparator.compare(t2, t1) > 0);

    innerComparator = comparators[1];
    assertTrue(innerComparator.compare(t1, t2) < 0);
    assertTrue(innerComparator.compare(t2, t1) > 0);
  }
Exemplo n.º 16
0
  @Test
  public void testInsteadOfTriggerIsDistinct() throws Exception {
    String ddl =
        "CREATE VIEW G1( e1 integer, e2 varchar) AS select * from foo;"
            + "CREATE TRIGGER ON G1 INSTEAD OF UPDATE AS "
            + "FOR EACH ROW \n"
            + "BEGIN ATOMIC \n"
            + "if (\"new\" is not distinct from \"old\") raise sqlexception 'error';\n"
            + "END;";

    Schema s = helpParse(ddl, "model").getSchema();

    assertEquals(
        "FOR EACH ROW\nBEGIN ATOMIC\nIF(\"new\" IS NOT DISTINCT FROM \"old\")\nBEGIN\nRAISE SQLEXCEPTION 'error';\nEND\nEND",
        s.getTable("G1").getUpdatePlan());
  }
Exemplo n.º 17
0
  /** It asserts the equality between an original table desc and a restored table desc. */
  private static void assertSchemaEquality(String tableName, Schema schema)
      throws IOException, TajoException {
    Path path = new Path(CommonTestingUtil.getTestDir(), tableName);
    TableDesc tableDesc =
        new TableDesc(
            IdentifierUtil.buildFQName(DEFAULT_DATABASE_NAME, tableName),
            schema,
            "TEXT",
            new KeyValueSet(),
            path.toUri());

    // schema creation
    assertFalse(catalog.existsTable(DEFAULT_DATABASE_NAME, tableName));
    catalog.createTable(tableDesc);
    assertTrue(catalog.existsTable(DEFAULT_DATABASE_NAME, tableName));

    // change it for the equals test.
    schema.setQualifier(IdentifierUtil.buildFQName(DEFAULT_DATABASE_NAME, tableName));
    TableDesc restored = catalog.getTableDesc(DEFAULT_DATABASE_NAME, tableName);
    assertEquals(schema, restored.getSchema());

    // drop test
    catalog.dropTable(IdentifierUtil.buildFQName(DEFAULT_DATABASE_NAME, tableName));
    assertFalse(catalog.existsTable(DEFAULT_DATABASE_NAME, tableName));
  }
Exemplo n.º 18
0
  @Test
  public void testUDT() throws Exception {
    String ddl =
        "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar OPTIONS (UDT 'NMTOKENS(12,13,14)'))";

    Schema s = helpParse(ddl, "model").getSchema();
    Map<String, Table> tableMap = s.getTables();

    assertTrue("Table not found", tableMap.containsKey("G1"));
    Table table = tableMap.get("G1");

    assertEquals("NMTOKENS", table.getColumns().get(1).getDatatype().getName());
    assertEquals(12, table.getColumns().get(1).getLength());
    assertEquals(13, table.getColumns().get(1).getPrecision());
    assertEquals(14, table.getColumns().get(1).getScale());
  }
Exemplo n.º 19
0
  @Test
  public void acceptVisitor() {
    DbObject dbo1 = Mockito.mock(DbObject.class);
    left.add(dbo1);
    DbObject dbo2 = Mockito.mock(DbObject.class);
    left.add(dbo2);
    DbObject dbo3 = Mockito.mock(DbObject.class);
    left.add(dbo3);

    left.accept(visitor);

    verify(dbo1).accept(visitor);
    verify(dbo2).accept(visitor);
    verify(dbo3).accept(visitor);
    verify(visitor).visit(left);
  }
Exemplo n.º 20
0
  @Test
  public void testConstraints2() throws Exception {
    String ddl =
        "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar, e3 date, "
            + "ACCESSPATTERN(e1), UNIQUE(e1), ACCESSPATTERN(e2, e3))";

    Schema s = helpParse(ddl, "model").getSchema();
    Map<String, Table> tableMap = s.getTables();

    assertTrue("Table not found", tableMap.containsKey("G1"));
    Table table = tableMap.get("G1");

    assertEquals(table.getColumns().subList(0, 1), table.getUniqueKeys().get(0).getColumns());
    assertEquals(2, table.getAccessPatterns().size());
    assertEquals(table.getColumns().subList(0, 1), table.getAccessPatterns().get(0).getColumns());
    assertEquals(table.getColumns().subList(1, 3), table.getAccessPatterns().get(1).getColumns());
  }
Exemplo n.º 21
0
  @Test
  public void testMultipleCommands() throws Exception {
    String ddl =
        "CREATE VIEW V1 AS SELECT * FROM PM1.G1 "
            + "CREATE PROCEDURE FOO(P1 integer) RETURNS (e1 integer, e2 varchar) AS SELECT * FROM PM1.G1;";

    Schema s = helpParse(ddl, "model").getSchema();
    Map<String, Table> tableMap = s.getTables();
    Table table = tableMap.get("V1");
    assertNotNull(table);
    assertEquals("SELECT * FROM PM1.G1", table.getSelectTransformation());

    Map<String, Procedure> procedureMap = s.getProcedures();
    Procedure p = procedureMap.get("FOO");
    assertNotNull(p);
    assertEquals("SELECT * FROM PM1.G1;", p.getQueryPlan());
  }
Exemplo n.º 22
0
  @Test
  public void testTypeLength() throws Exception {
    String ddl =
        "CREATE FOREIGN PROCEDURE myProc(OUT p1 boolean, p2 varchar, INOUT p3 decimal) "
            + "RETURNS (r1 varchar(10), r2 decimal(11,2), r3 object(1), r4 clob(10000))"
            + "OPTIONS(RANDOM 'any', UUID 'uuid', NAMEINSOURCE 'nis', ANNOTATION 'desc', UPDATECOUNT '2');";

    Schema s = helpParse(ddl, "model").getSchema();
    Procedure proc = s.getProcedure("myProc");
    assertNotNull(proc);

    List<Column> cols = proc.getResultSet().getColumns();
    assertEquals(10, cols.get(0).getLength());
    assertEquals(11, cols.get(1).getPrecision());
    assertEquals(1, cols.get(2).getLength());
    assertEquals(10000, cols.get(3).getLength());
  }
Exemplo n.º 23
0
  @BeforeClass
  public static void setUp() throws Exception {
    util = new TajoTestingCluster();
    util.startCatalogCluster();
    catalog = util.getMiniCatalogCluster().getCatalog();

    Schema schema = new Schema();
    schema.addColumn("name", Type.TEXT);
    schema.addColumn("empId", CatalogUtil.newSimpleDataType(Type.INT4));
    schema.addColumn("deptName", Type.TEXT);

    Schema schema2 = new Schema();
    schema2.addColumn("deptName", Type.TEXT);
    schema2.addColumn("manager", Type.TEXT);

    Schema schema3 = new Schema();
    schema3.addColumn("deptName", Type.TEXT);
    schema3.addColumn("score", CatalogUtil.newSimpleDataType(Type.INT4));

    TableMeta meta = CatalogUtil.newTableMeta(StoreType.CSV);
    TableDesc people = new TableDesc("employee", schema, meta, CommonTestingUtil.getTestDir());
    catalog.addTable(people);

    TableDesc student =
        new TableDesc(
            "dept", schema2, StoreType.CSV, new Options(), CommonTestingUtil.getTestDir());
    catalog.addTable(student);

    TableDesc score =
        new TableDesc(
            "score", schema3, StoreType.CSV, new Options(), CommonTestingUtil.getTestDir());
    catalog.addTable(score);

    FunctionDesc funcDesc =
        new FunctionDesc(
            "sumtest",
            SumInt.class,
            FunctionType.AGGREGATION,
            CatalogUtil.newSimpleDataType(Type.INT4),
            CatalogUtil.newSimpleDataTypeArray(Type.INT4));

    catalog.createFunction(funcDesc);
    analyzer = new SQLAnalyzer();
    planner = new LogicalPlanner(catalog);
  }
Exemplo n.º 24
0
  @Test
  public final void testGetJoinKeyPairs() {
    Schema outerSchema = new Schema();
    outerSchema.addColumn("employee.id1", CatalogUtil.newSimpleDataType(Type.INT4));
    outerSchema.addColumn("employee.id2", CatalogUtil.newSimpleDataType(Type.INT4));
    Schema innerSchema = new Schema();
    innerSchema.addColumn("people.fid1", CatalogUtil.newSimpleDataType(Type.INT4));
    innerSchema.addColumn("people.fid2", CatalogUtil.newSimpleDataType(Type.INT4));

    FieldEval f1 = new FieldEval("employee.id1", CatalogUtil.newSimpleDataType(Type.INT4));
    FieldEval f2 = new FieldEval("people.fid1", CatalogUtil.newSimpleDataType(Type.INT4));
    FieldEval f3 = new FieldEval("employee.id2", CatalogUtil.newSimpleDataType(Type.INT4));
    FieldEval f4 = new FieldEval("people.fid2", CatalogUtil.newSimpleDataType(Type.INT4));

    EvalNode joinQual = new BinaryEval(EvalType.EQUAL, f1, f2);

    // the case where part is the outer and partsupp is the inner.
    List<Column[]> pairs = PlannerUtil.getJoinKeyPairs(joinQual, outerSchema, innerSchema);
    assertEquals(1, pairs.size());
    assertEquals("employee.id1", pairs.get(0)[0].getQualifiedName());
    assertEquals("people.fid1", pairs.get(0)[1].getQualifiedName());

    // after exchange of outer and inner
    pairs = PlannerUtil.getJoinKeyPairs(joinQual, innerSchema, outerSchema);
    assertEquals("people.fid1", pairs.get(0)[0].getQualifiedName());
    assertEquals("employee.id1", pairs.get(0)[1].getQualifiedName());

    // composited join key test
    EvalNode joinQual2 = new BinaryEval(EvalType.EQUAL, f3, f4);
    EvalNode compositedJoinQual = new BinaryEval(EvalType.AND, joinQual, joinQual2);
    pairs = PlannerUtil.getJoinKeyPairs(compositedJoinQual, outerSchema, innerSchema);
    assertEquals(2, pairs.size());
    assertEquals("employee.id1", pairs.get(0)[0].getQualifiedName());
    assertEquals("people.fid1", pairs.get(0)[1].getQualifiedName());
    assertEquals("employee.id2", pairs.get(1)[0].getQualifiedName());
    assertEquals("people.fid2", pairs.get(1)[1].getQualifiedName());

    // after exchange of outer and inner
    pairs = PlannerUtil.getJoinKeyPairs(compositedJoinQual, innerSchema, outerSchema);
    assertEquals(2, pairs.size());
    assertEquals("people.fid1", pairs.get(0)[0].getQualifiedName());
    assertEquals("employee.id1", pairs.get(0)[1].getQualifiedName());
    assertEquals("people.fid2", pairs.get(1)[0].getQualifiedName());
    assertEquals("employee.id2", pairs.get(1)[1].getQualifiedName());
  }
Exemplo n.º 25
0
  @Test
  public void testVirtualProcedure() throws Exception {
    String ddl =
        "CREATE VIRTUAL PROCEDURE myProc(OUT p1 boolean, p2 varchar, INOUT p3 decimal) "
            + "RETURNS (r1 varchar, r2 decimal) "
            + "OPTIONS(RANDOM 'any', UUID 'uuid', NAMEINSOURCE 'nis', ANNOTATION 'desc', UPDATECOUNT '2') "
            + "AS /*+ cache */ BEGIN select * from foo; END";

    Schema s = helpParse(ddl, "model").getSchema();

    Procedure proc = s.getProcedure("myProc");
    assertNotNull(proc);

    assertTrue(proc.isVirtual());
    assertFalse(proc.isFunction());

    assertEquals(3, proc.getParameters().size());
    assertEquals("p1", proc.getParameters().get(0).getName());
    assertEquals("boolean", proc.getParameters().get(0).getDatatype().getName());
    assertEquals(ProcedureParameter.Type.Out, proc.getParameters().get(0).getType());

    assertEquals("p2", proc.getParameters().get(1).getName());
    assertEquals("string", proc.getParameters().get(1).getDatatype().getName());
    assertEquals(ProcedureParameter.Type.In, proc.getParameters().get(1).getType());

    assertEquals("p3", proc.getParameters().get(2).getName());
    assertEquals("bigdecimal", proc.getParameters().get(2).getDatatype().getName());
    assertEquals(ProcedureParameter.Type.InOut, proc.getParameters().get(2).getType());

    ColumnSet<Procedure> ret = proc.getResultSet();
    assertNotNull(ret);
    assertEquals(2, ret.getColumns().size());
    assertEquals("r1", ret.getColumns().get(0).getName());
    assertEquals("string", ret.getColumns().get(0).getDatatype().getName());
    assertEquals("r2", ret.getColumns().get(1).getName());
    assertEquals("bigdecimal", ret.getColumns().get(1).getDatatype().getName());

    assertEquals("uuid", proc.getUUID());
    assertEquals("nis", proc.getNameInSource());
    assertEquals("desc", proc.getAnnotation());
    assertEquals(2, proc.getUpdateCount());
    assertEquals("any", proc.getProperties().get("RANDOM"));

    assertEquals("/*+ cache */ BEGIN\nSELECT * FROM foo;\nEND", proc.getQueryPlan());
  }
Exemplo n.º 26
0
  @Test
  public void testAlterProcedureOptions() throws Exception {
    String ddl =
        "CREATE FOREIGN PROCEDURE myProc(OUT p1 boolean, p2 varchar, INOUT p3 decimal) "
            + "RETURNS (r1 varchar, r2 decimal)"
            + "OPTIONS(RANDOM 'any', UUID 'uuid', NAMEINSOURCE 'nis', ANNOTATION 'desc', UPDATECOUNT '2');"
            + "ALTER FOREIGN PROCEDURE myProc OPTIONS(SET NAMEINSOURCE 'x')"
            + "ALTER FOREIGN PROCEDURE myProc ALTER PARAMETER p2 OPTIONS (ADD x 'y');"
            + "ALTER FOREIGN PROCEDURE myProc OPTIONS(DROP UPDATECOUNT);";

    Schema s = helpParse(ddl, "model").getSchema();
    Procedure proc = s.getProcedure("myProc");
    assertNotNull(proc);

    assertEquals("x", proc.getNameInSource());
    assertEquals("p2", proc.getParameters().get(1).getName());
    assertEquals("y", proc.getParameters().get(1).getProperty("x", false));
    assertEquals(1, proc.getUpdateCount());
  }
Exemplo n.º 27
0
  @Test
  public void testInsteadOfTrigger() throws Exception {
    String ddl =
        "CREATE VIEW G1( e1 integer, e2 varchar) AS select * from foo;"
            + "CREATE TRIGGER ON G1 INSTEAD OF INSERT AS "
            + "FOR EACH ROW \n"
            + "BEGIN ATOMIC \n"
            + "insert into g1 (e1, e2) values (1, 'trig');\n"
            + "END;"
            + "CREATE View G2( e1 integer, e2 varchar) AS select * from foo;";

    Schema s = helpParse(ddl, "model").getSchema();
    Map<String, Table> tableMap = s.getTables();

    assertTrue("Table not found", tableMap.containsKey("G1"));
    assertTrue("Table not found", tableMap.containsKey("G2"));
    assertEquals(
        "FOR EACH ROW\nBEGIN ATOMIC\nINSERT INTO g1 (e1, e2) VALUES (1, 'trig');\nEND",
        s.getTable("G1").getInsertPlan());
  }
Exemplo n.º 28
0
  @Test
  public void testFK() throws Exception {
    String ddl =
        "CREATE FOREIGN TABLE G1(g1e1 integer, g1e2 varchar, PRIMARY KEY(g1e1, g1e2));\n"
            + "CREATE FOREIGN TABLE G2( g2e1 integer, g2e2 varchar, "
            + "FOREIGN KEY (g2e1, g2e2) REFERENCES G1 (g1e1, g1e2) options (\"teiid_rel:allow-join\" true))";

    Schema s = helpParse(ddl, "model").getSchema();
    Map<String, Table> tableMap = s.getTables();
    assertEquals(2, tableMap.size());

    assertTrue("Table not found", tableMap.containsKey("G1"));
    assertTrue("Table not found", tableMap.containsKey("G2"));

    Table table = tableMap.get("G2");
    ForeignKey fk = table.getForeignKeys().get(0);
    assertEquals(Boolean.TRUE.toString(), fk.getProperty(ForeignKey.ALLOW_JOIN, false));
    assertEquals(fk.getColumns(), table.getColumns());
    assertEquals("G1", fk.getReferenceTableName());
  }
Exemplo n.º 29
0
  @Test
  public void testAlterTableRemoveColumnOptions() throws Exception {
    String ddl =
        "CREATE FOREIGN TABLE G1( e1 integer OPTIONS (NULL_VALUE_COUNT 12, FOO 'BAR'), e2 varchar, e3 date);"
            + "ALTER FOREIGN TABLE G1 ALTER COLUMN e1 OPTIONS(DROP NULL_VALUE_COUNT);"
            + "ALTER FOREIGN TABLE G1 ALTER COLUMN e1 OPTIONS(DROP FOO);"
            + "ALTER FOREIGN TABLE G1 ALTER COLUMN e1 OPTIONS( ADD x 'y');";

    Schema s = helpParse(ddl, "model").getSchema();
    Map<String, Table> tableMap = s.getTables();

    assertTrue("Table not found", tableMap.containsKey("G1"));
    Table table = tableMap.get("G1");
    Column c = table.getColumnByName("e1");
    assertNotNull(c);

    assertNull(c.getProperty("FOO", false));
    assertEquals(-1, c.getNullValues());
    assertEquals("y", c.getProperty("x", false));
  }
Exemplo n.º 30
0
  @Test
  public void testAlterTableAddColumnOptions() throws Exception {
    String ddl =
        "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar, e3 date);"
            + "ALTER FOREIGN TABLE G1 OPTIONS(ADD CARDINALITY 12);"
            + "ALTER FOREIGN TABLE G1 ALTER COLUMN e1 OPTIONS(ADD NULL_VALUE_COUNT 12);"
            + "ALTER FOREIGN TABLE G1 ALTER COLUMN e1 OPTIONS(ADD FOO 'BAR');";

    Schema s = helpParse(ddl, "model").getSchema();
    Map<String, Table> tableMap = s.getTables();

    assertTrue("Table not found", tableMap.containsKey("G1"));
    Table table = tableMap.get("G1");
    assertEquals(12, table.getCardinality());
    Column c = table.getColumnByName("e1");
    assertNotNull(c);

    assertEquals("BAR", c.getProperty("FOO", false));
    assertEquals(12, c.getNullValues());
  }