FAQ
Hello,

I'm looking for help with UDFs.

I need a UDF to do something like this:
SELECT parseCoordinates(latitude, longitude) AS lat, lng FROM foo;

But I'm not sure how. I've implemented a UDF using GenericUDF
returning a struct with two fields and that works as in me getting
back a struct (e.g. "{"latitude":2.0,"longitude":10.0}") but that's
still one field and I don't know how to split that back in two
columns. I could obviously store that in an intermediate table but
that seems like a hassle and I'd like to avoid it.

Any ideas how to do this properly?

I've tried things like:
SELECT parseCoordinates(latitude, longitude) AS lat, lng FROM foo;
SELECT parseCoordinates(latitude, longitude) AS (lat, lng) FROM foo;
SELECT parseCoordinates(latitude, longitude) AS bar, bar.latitude AS
lat, bar.longitude AS lng FROM foo;

etc. but I always get an error: FAILED: Error in semantic analysis: AS
clause has an invalid number of aliases

Thanks a lot.

Cheers,
Lars

Search Discussions

  • John Sichi at Jan 13, 2011 at 8:48 pm
    SELECT bar.latitude, bar.longitude FROM
    (SELECT parseCoordinates(latitude, longitude) as coord FROM foo) bar;

    JVS
    SELECT parseCoordinates(latitude, longitude) AS lat, lng FROM foo;
    On Jan 13, 2011, at 10:10 AM, Lars Francke wrote:

    Hello,

    I'm looking for help with UDFs.

    I need a UDF to do something like this:
    SELECT parseCoordinates(latitude, longitude) AS lat, lng FROM foo;

    But I'm not sure how. I've implemented a UDF using GenericUDF
    returning a struct with two fields and that works as in me getting
    back a struct (e.g. "{"latitude":2.0,"longitude":10.0}") but that's
    still one field and I don't know how to split that back in two
    columns. I could obviously store that in an intermediate table but
    that seems like a hassle and I'd like to avoid it.

    Any ideas how to do this properly?

    I've tried things like:
    SELECT parseCoordinates(latitude, longitude) AS lat, lng FROM foo;
    SELECT parseCoordinates(latitude, longitude) AS (lat, lng) FROM foo;
    SELECT parseCoordinates(latitude, longitude) AS bar, bar.latitude AS
    lat, bar.longitude AS lng FROM foo;

    etc. but I always get an error: FAILED: Error in semantic analysis: AS
    clause has an invalid number of aliases

    Thanks a lot.

    Cheers,
    Lars
  • Lars Francke at Jan 14, 2011 at 1:27 pm
    Thank you very much!

    It worked with one small correction:

    SELECT coord.latitude, coord.longitude FROM
    (SELECT parseCoordinates(latitude, longitude) as coord FROM foo) bar;

    Going to test this some more now.

    Cheers,
    Lars

    PS: Sorry for sending this to the old list

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categorieshive, hadoop
postedJan 13, '11 at 6:12p
activeJan 14, '11 at 1:27p
posts3
users2
websitehive.apache.org

2 users in discussion

Lars Francke: 2 posts John Sichi: 1 post

People

Translate

site design / logo © 2021 Grokbase