예제 #1
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"));
  }
예제 #2
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());
  }
예제 #3
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());
  }
예제 #4
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());
  }
예제 #5
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());
  }
예제 #6
0
  @Test
  public void testUDAggregate() throws Exception {
    String ddl =
        "CREATE VIRTUAL FUNCTION SourceFunc(flag boolean, msg varchar) RETURNS varchar "
            + "OPTIONS(CATEGORY 'misc', AGGREGATE 'true', \"allows-distinct\" 'true', UUID 'y')";

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

    FunctionMethod fm = s.getFunction("y");
    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());
    assertNotNull(fm.getAggregateAttributes());
    assertTrue(fm.getAggregateAttributes().allowsDistinct());
    assertEquals(FunctionMethod.Determinism.DETERMINISTIC, fm.getDeterminism());
    assertEquals("misc", fm.getCategory());
    assertFalse(fm.isNullOnNull());
  }