示例#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
  private void visit(FunctionMethod function) {
    if (this.filter != null && !filter.matcher(function.getName()).matches()) {
      return;
    }
    append(CREATE).append(SPACE);
    if (function.getPushdown().equals(FunctionMethod.PushDown.MUST_PUSHDOWN)) {
      append(FOREIGN);
    } else {
      append(VIRTUAL);
    }
    append(SPACE)
        .append(FUNCTION)
        .append(SPACE)
        .append(SQLStringVisitor.escapeSinglePart(function.getName()));
    append(LPAREN);

    boolean first = true;
    for (FunctionParameter fp : function.getInputParameters()) {
      if (first) {
        first = false;
      } else {
        append(COMMA).append(SPACE);
      }
      visit(fp);
    }
    append(RPAREN);

    append(SPACE).append(RETURNS);
    appendOptions(function.getOutputParameter());
    append(SPACE);
    append(function.getOutputParameter().getType());

    // options
    String options = buildFunctionOptions(function);
    if (!options.isEmpty()) {
      append(NEWLINE).append(OPTIONS).append(SPACE).append(LPAREN).append(options).append(RPAREN);
    }

    /*if (function.getDefinition() != null) {
    	append(NEWLINE).append(SQLConstants.Reserved.AS).append(NEWLINE);
    	append(function.getDefinition());
    }*/

    append(SQLConstants.Tokens.SEMICOLON);
  }
示例#3
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());
  }
示例#4
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());
  }