Package io.druid.query.extraction

Examples of io.druid.query.extraction.JavascriptDimExtractionFn


  @Test
  public void testJavascriptSubstring()
  {
    String function = "function(str) { return str.substring(0,3); }";
    DimExtractionFn dimExtractionFn = new JavascriptDimExtractionFn(function);

    for (String str : testStrings) {
      String res = dimExtractionFn.apply(str);
      Assert.assertEquals(str.substring(0, 3), res);
    }
  }
View Full Code Here


  @Test
  public void testCastingAndNull()
  {
    String function = "function(x) {\n  x = Number(x);\n  if(isNaN(x)) return null;\n  return Math.floor(x / 5) * 5;\n}";
    DimExtractionFn dimExtractionFn = new JavascriptDimExtractionFn(function);

    Iterator<String> it = Iterators.forArray("0", "5", "5", "10", null);

    for(String str : Lists.newArrayList("1", "5", "6", "10", "CA")) {
      String res = dimExtractionFn.apply(str);
      String expected = it.next();
      Assert.assertEquals(expected, res);
    }
  }
View Full Code Here

  @Test
  public void testJavascriptRegex()
  {
    String function = "function(str) { return str.replace(/[aeiou]/g, ''); }";
    DimExtractionFn dimExtractionFn = new JavascriptDimExtractionFn(function);

    Iterator it = Iterators.forArray("Qt", "Clgry", "Tky", "Stckhlm", "Vncvr", "Prtr", "Wllngtn", "Ontr");
    for (String str : testStrings) {
      String res = dimExtractionFn.apply(str);
      Assert.assertEquals(it.next(), res);
    }
  }
View Full Code Here

                      + "\n"
                      + "    return w;"
                      + ""
                      + "}";

    DimExtractionFn dimExtractionFn = new JavascriptDimExtractionFn(function);

    Iterator<String> inputs = Iterators.forArray("introducing", "exploratory", "analytics", "on", "large", "datasets");
    Iterator<String> it = Iterators.forArray("introduc", "exploratori", "analyt", "on", "larg", "dataset");

    while(inputs.hasNext()) {
      String res = dimExtractionFn.apply(inputs.next());
      Assert.assertEquals(it.next(), res);
    }
  }
View Full Code Here

TOP

Related Classes of io.druid.query.extraction.JavascriptDimExtractionFn

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.