Java Code Examples for org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantStringObjectInspector

The following examples show how to use org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantStringObjectInspector. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: multiple-dimension-spread   Source File: BetweenHiveExpr.java    License: Apache License 2.0 6 votes vote down vote up
public static IExpressionNode getRangeExecuter( boolean invert , final PrimitiveObjectInspector minPrimitiveObjectInspector , final PrimitiveObjectInspector maxPrimitiveObjectInspector , final IExtractNode targetColumn ){
  switch( minPrimitiveObjectInspector.getPrimitiveCategory() ){
    case STRING:
      String minStr =  ( (WritableConstantStringObjectInspector)minPrimitiveObjectInspector ).getWritableConstantValue().toString();
      String maxStr =  ( (WritableConstantStringObjectInspector)maxPrimitiveObjectInspector ).getWritableConstantValue().toString();
      IFilter filter = new RangeStringCompareFilter( minStr , true , maxStr , true , invert );
      return new ExecuterNode( targetColumn , filter );
    case BYTE:
      return getNumberRangeExecuter( invert , new ByteObj( ( (WritableConstantByteObjectInspector)minPrimitiveObjectInspector ).getWritableConstantValue().get() ) , new ByteObj( ( (WritableConstantByteObjectInspector)maxPrimitiveObjectInspector ).getWritableConstantValue().get() ) , targetColumn );
    case SHORT:
      return getNumberRangeExecuter( invert , new ShortObj( ( (WritableConstantShortObjectInspector)minPrimitiveObjectInspector ).getWritableConstantValue().get() ) , new ShortObj( ( (WritableConstantShortObjectInspector)maxPrimitiveObjectInspector ).getWritableConstantValue().get() ) , targetColumn );
    case INT:
      return getNumberRangeExecuter( invert , new IntegerObj( ( (WritableConstantIntObjectInspector)minPrimitiveObjectInspector ).getWritableConstantValue().get() ) , new IntegerObj( ( (WritableConstantIntObjectInspector)maxPrimitiveObjectInspector ).getWritableConstantValue().get() ) , targetColumn );
    case LONG:
      return getNumberRangeExecuter( invert , new LongObj( ( (WritableConstantLongObjectInspector)minPrimitiveObjectInspector ).getWritableConstantValue().get() ) , new LongObj( ( (WritableConstantLongObjectInspector)maxPrimitiveObjectInspector ).getWritableConstantValue().get() ) , targetColumn );
    case FLOAT:
      return getNumberRangeExecuter( invert , new FloatObj( ( (WritableConstantFloatObjectInspector)minPrimitiveObjectInspector ).getWritableConstantValue().get() ) , new FloatObj( ( (WritableConstantFloatObjectInspector)maxPrimitiveObjectInspector ).getWritableConstantValue().get() ) , targetColumn );
    case DOUBLE:
      return getNumberRangeExecuter( invert , new DoubleObj( ( (WritableConstantDoubleObjectInspector)minPrimitiveObjectInspector ).getWritableConstantValue().get() ) , new DoubleObj( ( (WritableConstantDoubleObjectInspector)maxPrimitiveObjectInspector ).getWritableConstantValue().get() ) , targetColumn );
    default:
      return null;
  }
}
 
Example 2
Source Project: multiple-dimension-spread   Source File: RegexpHiveExpr.java    License: Apache License 2.0 5 votes vote down vote up
public static IExpressionNode getRegexpExecuter(final ExprNodeConstantDesc constDesc , final IExtractNode targetColumn ){
  ObjectInspector objectInspector = constDesc.getWritableObjectInspector();
  if( objectInspector.getCategory() != ObjectInspector.Category.PRIMITIVE ){
    return null;
  }
  PrimitiveObjectInspector primitiveObjectInspector = (PrimitiveObjectInspector)objectInspector;
  IFilter filter = null;
  switch( primitiveObjectInspector.getPrimitiveCategory() ){
    case STRING:
      String regexp = UDFLike.likePatternToRegExp( ( (WritableConstantStringObjectInspector)primitiveObjectInspector ).getWritableConstantValue().toString() );
      filter = new RegexpMatchStringFilter( "^" + regexp + "$" );
      break;
    case BINARY:
    case BOOLEAN:
    case BYTE:
    case DOUBLE:
    case FLOAT:
    case INT:
    case LONG:
    case SHORT:
    case DATE:
    case DECIMAL:
    case TIMESTAMP:
    case VOID:
    default:
      filter = null;
    break;
  }
  if( filter == null ){
    return null;
  }
  return new ExecuterNode( targetColumn , filter );
}
 
Example 3
Source Project: multiple-dimension-spread   Source File: InHiveExpr.java    License: Apache License 2.0 5 votes vote down vote up
public static IFilter getEqualsExecuter( final List<ExprNodeDesc> nodeDescList , final int start ){
  PrimitiveObjectInspector rootPrimitiveObjectInspector = getPrimitiveObjectInspector( nodeDescList.get( start ) );
  if( rootPrimitiveObjectInspector == null ){
    return null;
  }
  PrimitiveObjectInspector.PrimitiveCategory primitiveCategory = rootPrimitiveObjectInspector.getPrimitiveCategory();
  IFilter filter = null;
  switch( rootPrimitiveObjectInspector.getPrimitiveCategory() ){
    case STRING:
      Set<String> stringDic = new HashSet<String>();
      for( int i = start ; i < nodeDescList.size() ; i++ ){
        PrimitiveObjectInspector primitiveObjectInspector  = getPrimitiveObjectInspector( nodeDescList.get( i ) );
        if( primitiveObjectInspector == null || primitiveObjectInspector.getPrimitiveCategory() != rootPrimitiveObjectInspector.getPrimitiveCategory() ){
          return null;
        }
        stringDic.add( ( (WritableConstantStringObjectInspector)primitiveObjectInspector ).getWritableConstantValue().toString() );
      }
      return new StringDictionaryFilter( stringDic );
    case BYTE:
    case SHORT:
    case INT:
    case LONG:
    case FLOAT:
    case DOUBLE:
    default:
      return null;
  }
}
 
Example 4
Source Project: multiple-dimension-spread   Source File: CompareHiveExpr.java    License: Apache License 2.0 4 votes vote down vote up
public static IExpressionNode getCompareExecuter(final ExprNodeConstantDesc constDesc , final IExtractNode targetColumn , final StringCompareFilterType stringCompareType , final NumberFilterType numberCompareType ){
  ObjectInspector objectInspector = constDesc.getWritableObjectInspector();
  if( objectInspector.getCategory() != ObjectInspector.Category.PRIMITIVE ){
    return null;
  }
  PrimitiveObjectInspector primitiveObjectInspector = (PrimitiveObjectInspector)objectInspector;
  IFilter filter = null;
  switch( primitiveObjectInspector.getPrimitiveCategory() ){
    case STRING:
      switch( stringCompareType ){
        case LT:
          filter = new LtStringCompareFilter( ( (WritableConstantStringObjectInspector)primitiveObjectInspector ).getWritableConstantValue().toString() );
          break;
        case LE:
          filter = new LeStringCompareFilter( ( (WritableConstantStringObjectInspector)primitiveObjectInspector ).getWritableConstantValue().toString() );
          break;
        case GT:
          filter = new GtStringCompareFilter( ( (WritableConstantStringObjectInspector)primitiveObjectInspector ).getWritableConstantValue().toString() );
          break;
        case GE:
          filter = new GeStringCompareFilter( ( (WritableConstantStringObjectInspector)primitiveObjectInspector ).getWritableConstantValue().toString() );
          break;
        default:
          filter = null;
          break;
      }
      break;
    case BYTE:
      byte byteObj = ( (WritableConstantByteObjectInspector)primitiveObjectInspector ).getWritableConstantValue().get();
      filter = new NumberFilter( numberCompareType , new ByteObj( byteObj ) );
      break;
    case SHORT:
      short shortObj = ( (WritableConstantShortObjectInspector)primitiveObjectInspector ).getWritableConstantValue().get();
      filter = new NumberFilter( numberCompareType , new ShortObj( shortObj ) );
      break;
    case INT:
      int intObj = ( (WritableConstantIntObjectInspector)primitiveObjectInspector ).getWritableConstantValue().get();
      filter = new NumberFilter( numberCompareType , new IntegerObj( intObj ) );
      break;
    case LONG:
      long longObj = ( (WritableConstantLongObjectInspector)primitiveObjectInspector ).getWritableConstantValue().get();
      filter = new NumberFilter( numberCompareType , new LongObj( longObj ) );
      break;
    case FLOAT:
      float floatObj = ( (WritableConstantFloatObjectInspector)primitiveObjectInspector ).getWritableConstantValue().get();
      filter = new NumberFilter( numberCompareType , new FloatObj( floatObj ) );
      break;
    case DOUBLE:
      double doubleObj = ( (WritableConstantDoubleObjectInspector)primitiveObjectInspector ).getWritableConstantValue().get();
      filter = new NumberFilter( numberCompareType , new DoubleObj( doubleObj ) );
      break;
    case DATE:
    case DECIMAL:
    case TIMESTAMP:
      filter = null;
      break;
    default:
      filter = null;
      break;
  }
  if( filter == null ){
    return null;
  }
  return new ExecuterNode( targetColumn , filter );
}
 
Example 5
Source Project: multiple-dimension-spread   Source File: EqualsHiveExpr.java    License: Apache License 2.0 4 votes vote down vote up
public static IExpressionNode getEqualsExecuter( final ExprNodeConstantDesc constDesc , final IExtractNode targetColumn , final ColumnType targetColumnType ){
  ObjectInspector objectInspector = constDesc.getWritableObjectInspector();
  if( objectInspector.getCategory() != ObjectInspector.Category.PRIMITIVE ){
    return null;
  }
  PrimitiveObjectInspector primitiveObjectInspector = (PrimitiveObjectInspector)objectInspector;
  IFilter filter = null;
  switch( primitiveObjectInspector.getPrimitiveCategory() ){
    case STRING:
      filter = new PerfectMatchStringFilter( ( (WritableConstantStringObjectInspector)primitiveObjectInspector ).getWritableConstantValue().toString() );
      break;
    case BINARY:
      filter = null;
      break;
    case BOOLEAN:
      boolean booleanObj = ( (WritableConstantBooleanObjectInspector)primitiveObjectInspector ).getWritableConstantValue().get();
      filter = new BooleanFilter( booleanObj );
      break;
    case BYTE:
      byte byteObj = ( (WritableConstantByteObjectInspector)primitiveObjectInspector ).getWritableConstantValue().get();
      filter = new NumberFilter( NumberFilterType.EQUAL , new ByteObj( byteObj ) );
      break;
    case SHORT:
      short shortObj = ( (WritableConstantShortObjectInspector)primitiveObjectInspector ).getWritableConstantValue().get();
      filter = new NumberFilter( NumberFilterType.EQUAL , new ShortObj( shortObj ) );
      break;
    case INT:
      int intObj = ( (WritableConstantIntObjectInspector)primitiveObjectInspector ).getWritableConstantValue().get();
      filter = new NumberFilter( NumberFilterType.EQUAL , new IntegerObj( intObj ) );
      break;
    case LONG:
      long longObj = ( (WritableConstantLongObjectInspector)primitiveObjectInspector ).getWritableConstantValue().get();
      filter = new NumberFilter( NumberFilterType.EQUAL , new LongObj( longObj ) );
      break;
    case FLOAT:
      float floatObj = ( (WritableConstantFloatObjectInspector)primitiveObjectInspector ).getWritableConstantValue().get();
      filter = new NumberFilter( NumberFilterType.EQUAL , new FloatObj( floatObj ) );
      break;
    case DOUBLE:
      double doubleObj = ( (WritableConstantDoubleObjectInspector)primitiveObjectInspector ).getWritableConstantValue().get();
      filter = new NumberFilter( NumberFilterType.EQUAL , new DoubleObj( doubleObj ) );
      break;
    case DATE:
    case DECIMAL:
    case TIMESTAMP:
      filter = null;
      break;
    case VOID:
      Object voidObj = ( (WritableVoidObjectInspector)primitiveObjectInspector ).getWritableConstantValue();
      if( voidObj == null ){
        filter = new NullFilter( targetColumnType );
      }
      else{
        filter = null;
      }
      break;
    default:
      filter = null;
      break;
  }
  if( filter == null ){
    return null;
  }
  return new ExecuterNode( targetColumn , filter );
}
 
Example 6
Source Project: incubator-hivemall   Source File: HiveUtils.java    License: Apache License 2.0 4 votes vote down vote up
@Nonnull
public static WritableConstantStringObjectInspector getConstStringObjectInspector(
        @Nonnull final String str) {
    return (WritableConstantStringObjectInspector) PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(
        TypeInfoFactory.stringTypeInfo, new Text(str));
}
 
Example 7
Source Project: quetzal   Source File: WebServiceGetUDTF.java    License: Eclipse Public License 2.0 4 votes vote down vote up
@Override
public StructObjectInspector initialize(ObjectInspector[] parameters) throws UDFArgumentException {
	List<ObjectInspector> foi = new ArrayList<ObjectInspector>();
	List<String> l = new LinkedList<String>();
	
	inputColumns = new LinkedList<String>();
	xPathForColumns = new LinkedList<List<String>>();
	outputColumnNames = new HashMap<String, Integer>();


	int i = 0;
	while (i < parameters.length && parameters[i] instanceof WritableConstantStringObjectInspector) {
		WritableConstantStringObjectInspector wc = (WritableConstantStringObjectInspector) parameters[i];
		switch (i) {
		case 0:
			String str = wc.getWritableConstantValue().toString();
			System.out.println("handling output:" + str);
			handleOutputTypeSpecification(foi, str, l);
			i++;
			break;
		case 1:
			str = wc.getWritableConstantValue().toString();
			System.out.println("handling input:" + str);

			StringTokenizer tokenizer = new StringTokenizer(str, ",");
			while (tokenizer.hasMoreTokens()) {
				inputColumns.add(tokenizer.nextToken());
			}
			i++;
			break;
		case 2:
			queryText = wc.getWritableConstantValue().toString();
			System.out.println("handling queryText:" + queryText);
			i++;
			break;
		case 3:
			str = wc.getWritableConstantValue().toString();
			System.out.println("handling method:" + str);

			if (str.equals("GET")) {
				method = httpMethod.GET;
			} else {
				method = httpMethod.POST;
			}
			i++;
			break;
		case 4:
			System.out.println("handling namespaces:" + wc.getWritableConstantValue().toString());
			resolver = createNamespaces(wc.getWritableConstantValue().toString());
			i++;
			break;
		case 5:
			System.out.println("xpathforRows:" + wc.getWritableConstantValue().toString());
			xpathForRows = wc.getWritableConstantValue().toString();
			i++;
			break;
		default:
			addColXpathTuple(parameters, i);
			i += 3;
		}
	}
	indexOfInput = i; // Input starts where writable constants end
	System.out.println("xpathForColumns:" + xPathForColumns);
	System.out.println("Finished processing init");
	return ObjectInspectorFactory.getStandardStructObjectInspector(l, foi);

}