We make a lot of use of comparable for SQL value types. If we were to create
interface ComparableCharSequence
extends CharSequence, Comparable<ComparableCharSequence> {}
would you be able change your class to implement that rather than CharSequence?
Regarding your UDF. I’m not sure that we’ve ever tested UDFs whose argument
types do not match directly to a SQL type, so it probably doesn’t work. It
would make sense (probably we would match in terms of an on-the-fly
user-defined type, so we can stay within SQL’s type system).
Julian
> On Dec 8, 2015, at 6:22 AM, Matt Bateman <[email protected]> wrote:
>
> Hi,
>
> I have a row type object that has a CharSequence member called "name". It
> turns out I can't compare this with a "string" or character array in a SQL
> statement.
>
> For instance: "SELECT * FROM <table> WHERE name = 'FOO'"
>
> complains
>
> Cannot apply '=' to arguments of type '<JAVATYPE(INTERFACE
> JAVA.LANG.CHARSEQUENCE)> = <CHAR(3)>'. Supported form(s):
> '<COMPARABLE_TYPE> = <COMPARABLE_TYPE>'
>
> I think I get the issue, that CharSequence does not implement "Comparable".
> So I'm out of luck there.
>
> Then I figured I could create a function to convert a CharSequence into a
> character array or a string.
>
> So I have this:
>
> import org.apache.calcite.linq4j.function.Function1;
>
> public class CharSequenceToCharArrayFunction implements
> Function1<CharSequence, char[]> {
>
> public CharSequenceToCharArrayFunction() {
> System.out.println("Instantiated");
> }
>
> @Override
> public char[] apply(CharSequence str) {
> return str.toString().toCharArray();
> }
>
> }
>
> However, when I try it complains:
>
> No match found for function signature seqToChar(<JavaType(interface
> java.lang.CharSequence)>)
>
> My schema definition:
>
> {
> "version": "1.0",
> "defaultSchema": "USERS",
> "schemas":
> [
> {
> "name": "USERS",
> "type": "custom",
> "factory": "com.foo.calcite.CStoreSchemaFactory",
> "operand":
> {
> "directory": "/tmp"
> },
>
> "functions":
> [
> {
> "name": "seqToChar",
> "className":
> "com.foo.calcite.CharSequenceToCharArrayFunction",
> "methodName": "apply"
> }
> ]
> }
> ]
> }
>
> Any insight?