Hi again,

I modified this slightly and now it works (it's accepting ValueHolder and
resolving that function correctly)

regards,
 -Stefan

On Thu, Jan 14, 2016 at 8:25 AM, Stefán Baxter <ste...@activitystream.com>
wrote:

> Hi Jacques,
>
> I'm still struggling with this. The function you seem to be pointing me to
> is protected and I can not call it directly from my code.
>
> I created the same function in a local utility class:
>
> package com.activitystream.drill;
>
> public class ASDrillUtils {
>
>     public static String decodeString(java.nio.ByteBuffer src, 
> java.nio.charset.Charset charset) {
>         java.nio.charset.CharsetDecoder decoder = 
> io.netty.util.CharsetUtil.getDecoder(charset);
>         java.nio.CharBuffer dst = 
> java.nio.CharBuffer.allocate((int)((double)src.remaining() * 
> (double)decoder.maxCharsPerByte()));
>
>         try {
>             java.nio.charset.CoderResult x = decoder.decode(src, dst, true);
>             if(!x.isUnderflow()) {
>                 x.throwException();
>             }
>
>             x = decoder.flush(dst);
>             if(!x.isUnderflow()) {
>                 x.throwException();
>             }
>         } catch (java.nio.charset.CharacterCodingException var5) {
>             throw new IllegalStateException(var5);
>         }
>
>         return dst.flip().toString();
>     }
>
> }
>
> But when I try to call it I get the strangest error:
>
> Error: SYSTEM ERROR: CompileException: Line 146, Column 140: No applicable
> constructor/method found for actual parameters "java.nio.ByteBuffer,
> java.nio.charset.Charset"; candidates are: "/*default*/ static
> java.lang.String
> com.activitystream.drill.ASDrillUtils.decodeString(java.nio.ByteBuffer,
> java.nio.charset.Charset)"
>
> Fragment 4:1
>
> [Error Id: f544f3fd-c1fa-4a45-84e7-ae31ae095427 on Lightning:31010]
>
>
> Please note that the construct parameters and the expected classes match
> 100%
>
> Regards,
>  -Stefan
>
>
>
> On Tue, Jan 12, 2016 at 3:35 PM, Stefán Baxter <ste...@activitystream.com>
> wrote:
>
>>
>> OK, I came across this in some UDF sample code and welcome the "best
>> practices" update. :)
>>
>> Thank you,
>>  -Stefan
>>
>> On Tue, Jan 12, 2016 at 3:16 PM, Jacques Nadeau <jacq...@dremio.com>
>> wrote:
>>
>>> Inside Drill we generally don't use that method for anything but
>>> debugging.
>>> I'm working on some other fixes and will roll in a change to correct this
>>> as well. You should be able to track it via DRILL-4246. In the meantime,
>>> a
>>> workaround is using the ByteBufUtil that Drill uses internally for this
>>> kind of thing:
>>>
>>> DrillBuf myBuf = ...
>>> String bufAsString = ByteBufUtil.decodeString(myBuf.nioBuffer(),
>>> Charsets.UTF_8);
>>>
>>>
>>>
>>> --
>>> Jacques Nadeau
>>> CTO and Co-Founder, Dremio
>>>
>>> On Fri, Jan 8, 2016 at 12:04 PM, Stefán Baxter <
>>> ste...@activitystream.com>
>>> wrote:
>>>
>>> > So,
>>> >
>>> > This is happening due to changes made to DrillBuffer as a part of
>>> > Drill-4134 (53dcabeb83f53c8e29aff9c9282eaaa20a8b27ee)
>>> >
>>> > @Override
>>> >
>>> > public String toString(int index, int length, Charset charset) {
>>> >   final String basics =
>>> >       String.format("{DrillBuf[%d], udle identityHashCode == %d,
>>> > identityHashCode == %d}",
>>> >           id, System.identityHashCode(byteBuf),
>>> > System.identityHashCode(refCnt));
>>> >
>>> >   if (length == 0) {
>>> >     return basics;
>>> >   }
>>> >
>>> >   final ByteBuffer nioBuffer;
>>> >   if (nioBufferCount() == 1) {
>>> >     nioBuffer = nioBuffer(index, length);
>>> >   } else {
>>> >     nioBuffer = ByteBuffer.allocate(length);
>>> >     getBytes(index, nioBuffer);
>>> >     nioBuffer.flip();
>>> >   }
>>> >
>>> >   return basics + '\n' + ByteBufUtil.decodeString(nioBuffer, charset);
>>> > }
>>> >
>>> > Now the returned value is prefixed with the *basics* part.
>>> >
>>> > I have no idea what the intention is here but it must be breaking more
>>> > code than just mine.
>>> >
>>> > Its also interesting that this signature is formatted/created every
>>> > time a value is fetched.
>>> >
>>> > Regards,
>>> >  -Stefán
>>> >
>>> >
>>> >
>>> >
>>> > On Fri, Jan 8, 2016 at 7:48 PM, Stefán Baxter <
>>> ste...@activitystream.com>
>>> > wrote:
>>> >
>>> > > Hi again,
>>> > >
>>> > > This code can be used to reproduce this behavior:
>>> > >
>>> > > @FunctionTemplate(name = "asEcho", scope =
>>> > FunctionTemplate.FunctionScope.SIMPLE, nulls =
>>> > FunctionTemplate.NullHandling.NULL_IF_NULL)
>>> > > public static class asEcho implements DrillSimpleFunc {
>>> > >
>>> > >     @Param
>>> > >     VarCharHolder input1;
>>> > >
>>> > >     @Output
>>> > >     VarCharHolder output;
>>> > >
>>> > >     @Inject
>>> > >     DrillBuf buffer;
>>> > >
>>> > >     public void setup() { }
>>> > >
>>> > >     public void eval() {
>>> > >         String someValue = input1.buffer.toString(input1.start,
>>> > input1.end-input1.start, java.nio.charset.Charset.defaultCharset());
>>> > >         output.buffer = buffer.reallocIfNeeded(someValue.length());
>>> > >         for (Byte aByte : someValue.toString().getBytes())
>>> > output.buffer.setByte(output.end ++, aByte);
>>> > >     }
>>> > > }
>>> > >
>>> > >
>>> > >
>>> > >
>>> > >
>>> > > On Fri, Jan 8, 2016 at 7:43 PM, Stefán Baxter <
>>> ste...@activitystream.com
>>> > >
>>> > > wrote:
>>> > >
>>> > >> Hi,
>>> > >>
>>> > >> This seems to have something to do with reading string values from a
>>> > >> VarCharHolder.
>>> > >>
>>> > >> Here is the code that has stopped working:
>>> > >>
>>> > >> String someValue = input2.buffer.toString(input2.start,
>>> > input2.end-input2
>>> > >> .start, java.nio.charset.Charset.defaultCharset())
>>> > >>
>>> > >>
>>> > >> It used to return only the string value but now it returns:
>>> > >>
>>> > >> {DrillBuf[77], udle identityHashCode == 1660956802,
>>> identityHashCode ==
>>> > >> 343154168}
>>> > >> PT1H
>>> > >>
>>> > >>
>>> > >> The value is there in the second line (Seems to include a newline
>>> > >> character)
>>> > >>
>>> > >> Any ideas?
>>> > >>
>>> > >> Regards,
>>> > >>  -Stefan
>>> > >>
>>> > >>
>>> > >> On Fri, Jan 8, 2016 at 7:24 PM, Stefán Baxter <
>>> > ste...@activitystream.com>
>>> > >> wrote:
>>> > >>
>>> > >>> Hi,
>>> > >>>
>>> > >>> My UDFs have stopped working with the latest version of
>>> 1.5-SNAPSHOT
>>> > >>> (pulled just now).
>>> > >>>
>>> > >>> The error is:
>>> > >>> SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for
>>> > >>> further details.
>>> > >>> Error: SYSTEM ERROR: IllegalArgumentException: Invalid format:
>>> > >>> "{DrillBuf[74], udle identityHash..."
>>> > >>>
>>> > >>> Fragment 1:5
>>> > >>>
>>> > >>> [Error Id: 17b0165d-8ff3-4101-961a-0e40fdff0392 on Lightning:31010]
>>> > >>> (state=,code=0)
>>> > >>>
>>> > >>>
>>> > >>> Does anyone know what might be causing this?
>>> > >>>
>>> > >>> (The UDFs are compiled using the same target)
>>> > >>>
>>> > >>> Regards,
>>> > >>>  -Stefán
>>> > >>>
>>> > >>
>>> > >>
>>> > >
>>> >
>>>
>>
>>
>

Reply via email to