FAQ
Hi all,

Is the following a valid UDF please?

When I run it I get the following so I presume not:
hive> select toGoogleCoords(latitude,longitude,1) from
raw_occurrence_record limit 100;
FAILED: Error in semantic analysis:
java.lang.IllegalArgumentException: Error: name expected at the
position 7 of 'struct<>' but '>' is found.

Is it possible to return an Array from a UDF?

Thanks for any pointers,
Tim




public class GoogleTileCoordsUDF extends UDF {

public IntWritable[] evaluate(Text latitude, Text longitude,
IntWritable zoomLevel) {
if (latitude == null
longitude == null
zoomLevel == null) {
return null;
}

double lat = Double.parseDouble(latitude.toString());
double lng = Double.parseDouble(longitude.toString());

Point p = GoogleTileUtil.toTileXY(lat, lng, zoomLevel.get());

if (p==null) {
return null;
}

IntWritable[] xy = new IntWritable[2];
xy[0]=new IntWritable(p.x);
xy[1]=new IntWritable(p.y);
return xy;
}
}

Search Discussions

  • Edward Capriolo at Nov 2, 2010 at 5:40 pm

    On Tue, Nov 2, 2010 at 12:47 PM, Tim Robertson wrote:
    Hi all,

    Is the following a valid UDF please?

    When I run it I get the following so I presume not:
    hive> select toGoogleCoords(latitude,longitude,1) from
    raw_occurrence_record limit 100;
    FAILED: Error in semantic analysis:
    java.lang.IllegalArgumentException: Error: name expected at the
    position 7 of 'struct<>' but '>' is found.

    Is it possible to return an Array from a UDF?

    Thanks for any pointers,
    Tim




    public class GoogleTileCoordsUDF extends UDF {

    public IntWritable[] evaluate(Text latitude, Text longitude,
    IntWritable zoomLevel) {
    if (latitude == null
    longitude == null
    zoomLevel == null) {
    return null;
    }

    double lat = Double.parseDouble(latitude.toString());
    double lng = Double.parseDouble(longitude.toString());

    Point p = GoogleTileUtil.toTileXY(lat, lng, zoomLevel.get());

    if (p==null) {
    return null;
    }

    IntWritable[] xy = new IntWritable[2];
    xy[0]=new IntWritable(p.x);
    xy[1]=new IntWritable(p.y);
    return xy;
    }
    }
    I believe a UDF can not return an Array type. You may have to use the
    GenericUDF interface for that.
  • Tim Robertson at Nov 2, 2010 at 7:12 pm
    Thanks Edward. I'll poke around there.


    On Tue, Nov 2, 2010 at 6:40 PM, Edward Capriolo wrote:
    On Tue, Nov 2, 2010 at 12:47 PM, Tim Robertson
    wrote:
    Hi all,

    Is the following a valid UDF please?

    When I run it I get the following so I presume not:
    hive> select toGoogleCoords(latitude,longitude,1) from
    raw_occurrence_record limit 100;
    FAILED: Error in semantic analysis:
    java.lang.IllegalArgumentException: Error: name expected at the
    position 7 of 'struct<>' but '>' is found.

    Is it possible to return an Array from a UDF?

    Thanks for any pointers,
    Tim




    public class GoogleTileCoordsUDF extends UDF {

    public IntWritable[] evaluate(Text latitude, Text longitude,
    IntWritable zoomLevel) {
    if (latitude == null
    longitude == null
    zoomLevel == null) {
    return null;
    }

    double lat = Double.parseDouble(latitude.toString());
    double lng = Double.parseDouble(longitude.toString());

    Point p = GoogleTileUtil.toTileXY(lat, lng, zoomLevel.get());

    if (p==null) {
    return null;
    }

    IntWritable[] xy = new IntWritable[2];
    xy[0]=new IntWritable(p.x);
    xy[1]=new IntWritable(p.y);
    return xy;
    }
    }
    I believe a UDF can not return an Array type. You may have to use the
    GenericUDF interface for that.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categorieshive, hadoop
postedNov 2, '10 at 4:46p
activeNov 2, '10 at 7:12p
posts3
users2
websitehive.apache.org

2 users in discussion

Tim Robertson: 2 posts Edward Capriolo: 1 post

People

Translate

site design / logo © 2021 Grokbase