@Test public void testUserDefinedAggregateFunctionImplementsInterface() {
    final String empDept = JdbcTest.EmpDeptTableFactory.class.getName();
    final String mySum3 = Smalls.MySum3.class.getName();
    final String model = "{\n"
        + "  version: '1.0',\n"
        + "   schemas: [\n"
        + "     {\n"
        + "       name: 'adhoc',\n"
        + "       tables: [\n"
        + "         {\n"
        + "           name: 'EMPLOYEES',\n"
        + "           type: 'custom',\n"
        + "           factory: '" + empDept + "',\n"
        + "           operand: {'foo': true, 'bar': 345}\n"
        + "         }\n"
        + "       ],\n"
        + "       functions: [\n"
        + "         {\n"
        + "           name: 'MY_SUM3',\n"
        + "           className: '" + mySum3 + "'\n"
        + "         }\n"
        + "       ]\n"
        + "     }\n"
        + "   ]\n"
        + "}";
    final CalciteAssert.AssertThat with = CalciteAssert.model(model)
        .withDefaultSchema("adhoc");
    with.query("select my_sum3(\"deptno\") as p from EMPLOYEES\n")
        .returns("P=50\n");
    with.withDefaultSchema(null)
        .query("select \"adhoc\".my_sum3(\"deptno\") as p\n"
            + "from \"adhoc\".EMPLOYEES\n")
        .returns("P=50\n");
    with.query("select my_sum3(\"empid\"), \"deptno\" as p from EMPLOYEES\n")
        .throws_("Expression 'deptno' is not being grouped");
    with.query("select my_sum3(\"deptno\") as p from EMPLOYEES\n")
        .returns("P=50\n");
    with.query("select my_sum3(\"name\") as p from EMPLOYEES\n")
        .throws_("No match found for function signature MY_SUM3(<CHARACTER>)");
    with.query("select my_sum3(\"deptno\", 1) as p from EMPLOYEES\n")
        .throws_("No match found for function signature "
            + "MY_SUM3(<NUMERIC>, <NUMERIC>)");
    with.query("select my_sum3() as p from EMPLOYEES\n")
        .throws_("No match found for function signature MY_SUM3()");
    with.query("select \"deptno\", my_sum3(\"deptno\") as p from EMPLOYEES\n"
        + "group by \"deptno\"")
        .returnsUnordered("deptno=20; P=20",
            "deptno=10; P=30");
  }
@Test public void testUserDefinedAggregateFunctionImplementsInterface() {
    final String empDept = JdbcTest.EmpDeptTableFactory.class.getName();
    final String mySum3 = Smalls.MySum3.class.getName();
    final String model = "{\n"
        + "  version: '1.0',\n"
        + "   schemas: [\n"
        + "     {\n"
        + "       name: 'adhoc',\n"
        + "       tables: [\n"
        + "         {\n"
        + "           name: 'EMPLOYEES',\n"
        + "           type: 'custom',\n"
        + "           factory: '" + empDept + "',\n"
        + "           operand: {'foo': true, 'bar': 345}\n"
        + "         }\n"
        + "       ],\n"
        + "       functions: [\n"
        + "         {\n"
        + "           name: 'MY_SUM3',\n"
        + "           className: '" + mySum3 + "'\n"
        + "         }\n"
        + "       ]\n"
        + "     }\n"
        + "   ]\n"
        + "}";
    final CalciteAssert.AssertThat with = CalciteAssert.model(model)
        .withDefaultSchema("adhoc");
    with.query("select my_sum3(\"deptno\") as p from EMPLOYEES\n")
        .returns("P=50\n");
    with.withDefaultSchema(null)
        .query("select \"adhoc\".my_sum3(\"deptno\") as p\n"
            + "from \"adhoc\".EMPLOYEES\n")
        .returns("P=50\n");
    with.query("select my_sum3(\"empid\"), \"deptno\" as p from EMPLOYEES\n")
        .throws_("Expression 'deptno' is not being grouped");
    with.query("select my_sum3(\"deptno\") as p from EMPLOYEES\n")
        .returns("P=50\n");
    with.query("select my_sum3(\"name\") as p from EMPLOYEES\n")
        .throws_("No match found for function signature MY_SUM3(<CHARACTER>)");
    with.query("select my_sum3(\"deptno\", 1) as p from EMPLOYEES\n")
        .throws_("No match found for function signature "
            + "MY_SUM3(<NUMERIC>, <NUMERIC>)");
    with.query("select my_sum3() as p from EMPLOYEES\n")
        .throws_("No match found for function signature MY_SUM3()");
    with.query("select \"deptno\", my_sum3(\"deptno\") as p from EMPLOYEES\n"
        + "group by \"deptno\"")
        .returnsUnordered("deptno=20; P=20",
            "deptno=10; P=30");
  }
@test public void testuserdefinedaggregatefunctionimplementsinterface() { final string empdept = jdbctest.empdepttablefactory.class.getname(); final string mysum3 = smalls.mysum3.class.getname(); final string model = "{\n" + " version: '1.0',\n" + " schemas: [\n" + " {\n" + " name: 'adhoc',\n" + " tables: [\n" + " {\n" + " name: 'employees',\n" + " type: 'custom',\n" + " factory: '" + empdept + "',\n" + " operand: {'foo': true, 'bar': 345}\n" + " }\n" + " ],\n" + " functions: [\n" + " {\n" + " name: 'my_sum3',\n" + " classname: '" + mysum3 + "'\n" + " }\n" + " ]\n" + " }\n" + " ]\n" + "}"; final calciteassert.assertthat with = calciteassert.model(model) .withdefaultschema("adhoc"); with.query("select my_sum3(\"deptno\") as p from employees\n") .returns("p=50\n"); with.withdefaultschema(null) .query("select \"adhoc\".my_sum3(\"deptno\") as p\n" + "from \"adhoc\".employees\n") .returns("p=50\n"); with.query("select my_sum3(\"empid\"), \"deptno\" as p from employees\n") .throws_("expression 'deptno' is not being grouped"); with.query("select my_sum3(\"deptno\") as p from employees\n") .returns("p=50\n"); with.query("select my_sum3(\"name\") as p from employees\n") .throws_("no match found for function signature my_sum3(<character>)"); with.query("select my_sum3(\"deptno\", 1) as p from employees\n") .throws_("no match found for function signature " + "my_sum3(<numeric>, <numeric>)"); with.query("select my_sum3() as p from employees\n") .throws_("no match found for function signature my_sum3()"); with.query("select \"deptno\", my_sum3(\"deptno\") as p from employees\n" + "group by \"deptno\"") .returnsunordered("deptno=20; p=20", "deptno=10; p=30"); }