asterixdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Xikui Wang <xik...@uci.edu>
Subject Re: Derived types in Java UDF?
Date Wed, 13 Mar 2019 05:12:52 GMT
I think the example that you showed should work for you. Isn't it? If it's
a primitive type, you could use the data type in BuiltinType,
e.g., BuiltinType.ASTRING. If it's derived type, then you would have to
construct an ARecord type as the way that you did in your example. As you
may have noticed, the open/close flag of the constructed type should be
consistent with your DDLs. In your case, they are both closed. If they are
not consistent, there could be serialization issues. I tried to construct a
small test case with open data type based on the UpperCaseFunction, and it
works for me well. Here is the code snippet. You could move the data type
constructions into the initialization method to avoid creating them
repeatedly.

Java UDF:
...
        JRecord result = (JRecord) functionHelper.getResultObject();
        result.setField("id", id);
        result.setField("text", text);
        String[] capFields = { "text" };
        IAType[] capFieldTypes = { BuiltinType.ASTRING };
        ARecordType capRecordType = new ARecordType("CapitalizedType",
capFields, capFieldTypes, *true*);
        IJObject[] capFieldVals = { new JString("New field") };
        JRecord capRecord = new JRecord(capRecordType, capFieldVals);
        JOrderedList capitalized = new JOrderedList(capRecordType);
        capitalized.add(capRecord);
        result.setField("capitalized", capitalized);
        functionHelper.setResult(result);
...

DDLs:
create type TextType if not exists as open {
    id: int32,
    text: string
};

create type CapitalizedType as *open* {
    text: string
};

create type OutputTextType as open {
    id: int32,
    text: string,
    capitalized: [CapitalizedType]
};

Best,
Xikui

On Tue, Mar 12, 2019 at 6:19 AM sandraskarshaug@gmail.com <
sandraskarshaug@gmail.com> wrote:

>
>
> On 2019/03/12 12:19:38, sandraskarshaug@gmail.com <
> sandraskarshaug@gmail.com> wrote:
> > Does this make sense in order to add TermFrequencyType objects to
> termFrequencies?
> >
> > termFrequencies.add(
> >      new JRecord(
> >          new ARecordType("TermFrequencyType", getTermFrequencyFields(),
> getFieldTypes(), false),
> >          new IJObject[]{ new JString("hello"), new JInt(1) }
> >      )
> > );
> >
> > And have I understood it correctly if I implement getFieldTypes() like
> this:
> >
> > IAType[] getFieldTypes() {
> >    return new IAType[]{BuiltinType.ASTRING, BuiltinType.AINT32};
> > }
> >
> >
> >
>
> Excuse me, I of course ment which implementation of the IAType interface I
> should use :-)
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message