Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6936457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:14:09+00:00 2026-05-27T12:14:09+00:00

I am having some problems with regexp_extract: I am querying on a tab-delimited file,

  • 0

I am having some problems with regexp_extract:

I am querying on a tab-delimited file, the column I’m checking has strings that look like this:

abc.def.ghi

Now, if I do:

select distinct regexp_extract(name, '[^.]+', 0) from dummy;

MR job runs, it works, and I get “abc” from index 0.

But now, if I want to get “def” from index 1:

select distinct regexp_extract(name, '[^.]+', 1) from dummy;

Hive fails with:

2011-12-13 23:17:08,132 Stage-1 map = 0%,  reduce = 0%
2011-12-13 23:17:28,265 Stage-1 map = 100%,  reduce = 100%
Ended Job = job_201112071152_0071 with errors
FAILED: Execution Error, return code 2 from org.apache.hadoop.hive.ql.exec.MapRedTask

Log file says:

java.lang.RuntimeException: org.apache.hadoop.hive.ql.metadata.HiveException: Hive Runtime Error while processing row

Am I doing something fundamentally wrong here?

Thanks,
Mario

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:14:10+00:00Added an answer on May 27, 2026 at 12:14 pm

    From the docs https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF it appears that regexp_extract() is a record/line extraction of the data you wish to extract.

    It seems to work on a first found (then quit) as opposed to global. Therefore the index references the capture group.

    0 = the entire match
    1 = capture group 1
    2 = capture group 2, etc …

    Paraphrased from the manual:

    regexp_extract('foothebar', 'foo(.*?)(bar)', 2)
                                      ^    ^   
                   groups             1    2
    
    This returns 'bar'.
    

    So, in your case, to get the text after the dot, something like this might work:
    regexp_extract(name, '\.([^.]+)', 1)
    or this
    regexp_extract(name, '[.]([^.]+)', 1)

    edit

    I got re-interested in this, just a fyi, there could be a shortcut/workaround for you.

    It looks like you want a particular segment separated with a dot . character, which is almost like split.
    Its more than likely the regex engine used overwrites a group if it is quantified more than once.
    You can take advantage of that with something like this:

    Returns the first segment: abc.def.ghi
    regexp_extract(name, '^(?:([^.]+)\.?){1}', 1)

    Returns the second segment: abc.def.ghi
    regexp_extract(name, '^(?:([^.]+)\.?){2}', 1)

    Returns the third segment: abc.def.ghi
    regexp_extract(name, '^(?:([^.]+)\.?){3}', 1)

    The index doesn’t change (because the index still referrs to capture group 1), only the regex repetition changes.

    Some notes:

    • This regex ^(?:([^.]+)\.?){n} has problems though.
      It requires there be something between dots in the segment or the regex won’t match ....

    • It could be this ^(?:([^.]*)\.?){n} but this will match even if there is less than n-1 dots,
      including the empty string. This is probably not desireable.

    There is a way to do it where it doesn’t require text between the dots, but still requires at least n-1 dots.
    This uses a lookahead assertion and capture buffer 2 as a flag.

    ^(?:(?!\2)([^.]*)(?:\.|$())){2} , everything else is the same.

    So, if it uses java style regex, then this should work.
    regexp_extract(name, '^(?:(?!\2)([^.]*)(?:\.|$())){2}', 1) change {2} to whatever ‘segment’ is needed (this does segment 2).

    and it still returns capture buffer 1 after the {N}’th iteration.

    Here it is broken down

    ^                # Begining of string
     (?:             # Grouping
        (?!\2)            # Assertion: Capture buffer 2 is UNDEFINED
        ( [^.]*)          # Capture buffer 1, optional non-dot chars, many times
        (?:               # Grouping
            \.                # Dot character
          |                 # or,
            $ ()              # End of string, set capture buffer 2 DEFINED (prevents recursion when end of string)
        )                 # End grouping
     ){3}            # End grouping, repeat group exactly 3 (or N) times (overwrites capture buffer 1 each time)
    

    If it doesn’t do assertions, then this won’t work!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently having some problems- now = datetime.datetime.now() month = now.strftime(%B) site = wikipedia.getSite('en', 'wikiquote')
Im having some problems getting the Sticky Footer to work on my site. If
Im having some problems with a simple toggle in Safari. A really annoying flickering
I'm having some problems integrating MS MapPoint 2009 into my WinForms .Net 2.0 application
I have been having some problems trying to get my PHP running. When I
I'm having some problems with the ranking used by fulltext search in SQL Server.
I'm having some problems with a datagridview element I'm using in VS2008. This DataGridView
I'm having some problems getting my object to gracefully fail out if an invalid
I'm having some problems with the following code: private class ClientPluginLoader : MarshalByRefObject {
I'm having some problems with my WCF server and client connections. If I use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.