Hitachi Vantara Pentaho Community Forums
Results 1 to 12 of 12

Thread: phone number dimension with google libphonenumber

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2011
    Posts
    159

    Default phone number dimension with google libphonenumber

    Greetings all.

    I would like to build a phone number dimension (for use in a data model) where I will have a list of phone numbers and I'd like to add columns such as city/state/country data, isValid, etc.

    Google Code has a project: https://code.google.com/p/libphonenumber/

    but I don't see a readily available API for it (that is, no hosting service I see that I can, say, send JSON to).

    So, I'm not sure 'how' I can leverage the available *.jar files they have and KETTLE to do this - any leads I can read/research/test? I am a moderate kettle user, but never attempted anything this 'interesting' if you will.

    My thinking is there has to be a way to pass this list of numbers to 'something' that returns all the parms, but the 'how the something works' is something my rookie mind is lost at right now.

    Again, looking for some conversation/direction/ideas.

    Many many thanks!

  2. #2
    Join Date
    Nov 2008
    Posts
    777

    Default

    You should be able to place the .jar file in Kettle's /libext folder and then call the parsing methods in a JavaScript step. Let us know if you need help with that.

    I'm curious, though, how you are going to get the city/state from the phone number. It seems to me that the API provides only the country (code).
    pdi-ce-4.4.0-stable
    Java 1.7 (64 bit)
    MySQL 5.6 (64 bit)
    Windows 7 (64 bit)

  3. #3
    Join Date
    Apr 2011
    Posts
    159

    Default

    this is a GREAT start, thank you! I had no idea I could toss it in there and 'get access' to those methods. I will have to research next the JavaScript step and read more about the libphonenumber project.

    I haven't fully thought though the city/state data, but I know it's something I want to add/build into the dimension table. I'll start with CC and then try to solve that. I believe you are correct and I will not be able to get that from that project. i may have access to a CCMI (http://www.ccmi.com/) table I can use, but baby steps!

  4. #4
    Join Date
    Nov 2008
    Posts
    777

    Default

    Here's a post from some time ago that demonstrates using Java methods in a JavaScript step. If you use the "var" qualifier on the variables you want to output to the next step, then the "Get variables" button will pick them up and fill them into the table at the bottom of the step configuration screen.

    http://forums.pentaho.com/showthread...977#post322977

    I'm sure there are many other examples in this forum as well.
    pdi-ce-4.4.0-stable
    Java 1.7 (64 bit)
    MySQL 5.6 (64 bit)
    Windows 7 (64 bit)

  5. #5
    Join Date
    Apr 2011
    Posts
    159

    Default

    Thanks.

    Do I have to 'load' the classes (the jar file) in some way? I noticed in your example thread there is inflator = 'new java.util.zip.Inflater()' but I am lost on how I do something similar with this jar file.

    For perspective, my first step is grapping a single record (a raw number) from a table - might as well be "SELECT '15551234567' as myStr FROM DUAL" for this example's sake.

    My next step is the Modified Java Script Value.

    From there I tried to establish the example Java section of the code.google.com home page for libphonenumber:

    String swissNumberStr = myStr
    PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
    try {
    PhoneNumber swissNumberProto = phoneUtil.parse(swissNumberStr, "CH");
    } catch (NumberParseException e) {
    System.err.println("NumberParseException was thrown: " + e.toString());
    }

    it balked at the first line.

    I am guessing that's because it's a java example (not javascript), but I thought that is what you were saying about using Java methods in a Javascript step.

    In the end, I'm obviously rookie-level here, but I think I'm missing something with my environment - how to establish that step should be using the objects/methods available in that jar file.

    Does that make sense? Or, then, again, I may be way off!!!!

    I really appreciate the guidance.

  6. #6
    Join Date
    Nov 2008
    Posts
    777

    Default

    No loading of the jar file is required. You really don't have to import the classes either.

    Indeed, JavaScript is not Java! Here is how I would get going with the Google API:

    Code:
    /* Grab the parser. */
    phoneUtil = com.google.i18n.phonenumbers.PhoneNumberUtil.getInstance();
    
    /* Parse the phone number. */
    var proto = null;
    try {
        proto = phoneUtil.parse(myStr, "US");
    } catch (error) {
        proto = error.toString();
    }
    Attached Files Attached Files
    pdi-ce-4.4.0-stable
    Java 1.7 (64 bit)
    MySQL 5.6 (64 bit)
    Windows 7 (64 bit)

  7. #7
    Join Date
    Aug 2017
    Posts
    1

    Default

    Hi,

    So I tried to do almost the same thing:
    phoneUtil = com.google.i18n.phonenumbers.PhoneNumberUtil.getInstance();
    proto = phoneUtil.parse(myStr, "US");phone_number.ktrphone_number.ktrphone_number.ktr

    But I'm getting an error:
    2017/08/25 16:25:48 - Modified Java Script Value 2.0 - Javascript error:
    2017/08/25 16:25:48 - Modified Java Script Value 2.0 - Cannot convert 044 668 18 00 to java.lang.CharSequence (script#2)

    Then I have switched to:
    proto = phoneUtil.parse(myStr.toString(), "US");

    And it works. But the source field is already set as String, so why the conversion to string is still required?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.