Member since
03-21-2018
2
Posts
0
Kudos Received
0
Solutions
03-21-2018
10:57 PM
Hi , I have created a UDTF , that should take string(comma or space seperated) and should return them in multiple records . i.e. input1 : "this,is,me" Output1 : this is me input2 : "this is me" Output2 : this is me But I am not getting the output from UDTF . I have gone through all the related posts but nothing worked out. Please advise. Note : I am creating the jar, creating temp function and then quering like select fun(string). Please find below the code snippet : package obj.udf; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.apache.hadoop.hive.ql.exec.UDFArgumentException; import org.apache.hadoop.hive.ql.metadata.HiveException; import org.apache.hadoop.hive.ql.udf.generic.GenericUDF; import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory; import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; public class ParseString extends GenericUDF { private PrimitiveObjectInspector stringOI = null; //Collector collector = null; @Override public StructObjectInspector initialize(ObjectInspector[] args) throws UDFArgumentException { if (args.length != 1) { throw new UDFArgumentException( "Only one argument is allowed"); } if (args[0].getCategory() != ObjectInspector.Category.PRIMITIVE && ((PrimitiveObjectInspector) args[0]).getPrimitiveCategory() != PrimitiveObjectInspector.PrimitiveCategory.STRING) { throw new UDFArgumentException( "Only Primitive types are accepted"); } // input inspectors stringOI = (PrimitiveObjectInspector) args[0]; // output inspectors -- an object with three fields! List<String> fieldName = new ArrayList<String>(1); List<ObjectInspector> fieldOI = new ArrayList<ObjectInspector>(1); fieldName.add("selection"); fieldOI.add(PrimitiveObjectInspectorFactory.javaStringObjectInspector); return ObjectInspectorFactory.getStandardStructObjectInspector( fieldName, fieldOI); } public ArrayList<Object[]> processInputRecord(String selection) { ArrayList<Object[]> result = new ArrayList<Object[]>(); // ignoring null or empty input if (selection == null || selection.isEmpty()) { return result; } String[] tokens = null; if(selection.contains(",")) { tokens=selection.split(","); } if(selection.contains(" ")) { tokens=selection.split("\\s+"); } for(String s : tokens) { if(!s.isEmpty()) { result.add(new Object[] {s}); } } return result; } public void process(Object[] record) throws HiveException { final String selection = stringOI.getPrimitiveJavaObject(record[0]).toString(); ArrayList<Object[]> results = processInputRecord(selection); Iterator<Object[]> it = results.iterator(); while (it.hasNext()) { Object[] r = it.next(); forward(r); } } private void forward(Object[] r) { // TODO Auto-generated method stub } public void close() throws HiveException { // do nothing } @Override public Object evaluate(DeferredObject[] arg0) throws HiveException { // TODO Auto-generated method stub return null; } @Override public String getDisplayString(String[] arg0) { // TODO Auto-generated method stub return null; } }
... View more
Labels:
- Labels:
-
Apache Hive
-
Apache Impala
03-21-2018
12:09 AM
I am working on a poc where I have to connect my ssrs report to fetch data from impala based on the user selection made and display it in report. To get the required data , i have created a dataset , connected it to Impala data source , and passed argument. But it is not working out. sample query : Select * from table where user_selection=@param Here 'param' is defined under parameter folder of SSRS report and also pointing in the current dataset. also , instead of @ - I have tried :param,?param,${param},[param],[@param] and many more ... but nothing worked out. Please let me know your thoughts. PS : I have posted the same on SSRS forum as well.
... View more
Labels:
- Labels:
-
Apache Hive
-
Apache Impala