hive-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Robertson <timrobertson...@gmail.com>
Subject Only a single expression in the SELECT clause is supported with UDTF's
Date Mon, 08 Nov 2010 08:41:25 GMT
Hi all,

I am trying my first UDTF, but can't seem to get it to run.  Can
anyone spot anything wrong with this please:

hive> select taxonDensityUDTF(kingdom_concept_id, phylum_concept_id)
as p,k from temp_kingdom_phylum;
FAILED: Error in semantic analysis: Only a single expression in the
SELECT clause is supported with UDTF's
hive>

Below is my code.  Thanks for any pointers,

Tim



@description(
		  name = "taxonDensityUDTF",
		  value = "_FUNC_(kingdom_concept_id, phylum_concept_id)"
		)
public class TaxonDensityUDTF extends GenericUDTF {
	Integer kingdom_concept_id = Integer.valueOf(0);
	Integer phylum_concept_id = Integer.valueOf(0);
	
	/**
	 * @see org.apache.hadoop.hive.ql.udf.generic.GenericUDTF#close()
	 */
	@Override
	public void close() throws HiveException {
		Object[] forwardObj = new Object[2];
		forwardObj[0] = kingdom_concept_id;
		forwardObj[1] = phylum_concept_id;
		forward(forwardObj);
                // TEST STUFF FOR NOW
		forwardObj = new Object[2];
		forwardObj[0] = kingdom_concept_id+1;
		forwardObj[1] = phylum_concept_id+1;
		forward(forwardObj);		
	}

	/**
	 * @see org.apache.hadoop.hive.ql.udf.generic.GenericUDTF#initialize(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector[])
	 */
	@Override
	public StructObjectInspector initialize(ObjectInspector[] arg0)
throws UDFArgumentException {
		ArrayList<String> fieldNames = new ArrayList<String>();
		ArrayList<ObjectInspector> fieldOIs = new ArrayList<ObjectInspector>();
		fieldNames.add("kingdom_concept_id");
		fieldNames.add("phylum_concept_id");
		fieldOIs.add(PrimitiveObjectInspectorFactory.javaIntObjectInspector);
		fieldOIs.add(PrimitiveObjectInspectorFactory.javaIntObjectInspector);
		return ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames,fieldOIs);
	}

	/**
	 * @see org.apache.hadoop.hive.ql.udf.generic.GenericUDTF#process(java.lang.Object[])
	 */
	@Override
	public void process(Object[] args) throws HiveException {
		kingdom_concept_id = (Integer) args[0];
		phylum_concept_id = (Integer) args[1];
	}
}

Mime
View raw message