org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc Java Examples

The following examples show how to use org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc. 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 File: DynamoDBFilterFactory.java    From emr-dynamodb-connector with Apache License 2.0 6 votes vote down vote up
public DynamoDBFilter getFilter(DynamoDBFilterOperator operator, String columnName, String
    columnType, IndexSearchCondition condition) {
  switch (operator.getType()) {
    case UNARY:
      return getFilter(operator, columnName, columnType);
    case BINARY:
      return getFilter(operator, columnName, columnType, condition.getConstantDesc().getValue()
          .toString());
    case NARY:
      List<ExprNodeDesc> children = ShimsLoader.getHiveShims().getIndexExpression(condition)
          .getChildren();
      String[] values = new String[children.size() - 1];
      // This currently supports IN clause only
      // The first element is column name and rest of the elements are
      // the values it can take
      for (int i = 1; i < children.size(); i++) {
        values[i - 1] = ((ExprNodeConstantDesc) children.get(i)).getValue().toString();
      }
      return getFilter(operator, columnName, columnType, values);
    default:
      throw new RuntimeException("Unknown operator type. Operator: " + operator + " "
          + "OperatorType: " + operator.getType());
  }
}
 
Example #2
Source File: RegexpHiveExpr.java    From multiple-dimension-spread with 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 File: InHiveExpr.java    From multiple-dimension-spread with Apache License 2.0 5 votes vote down vote up
public static PrimitiveObjectInspector getPrimitiveObjectInspector( final ExprNodeDesc exprNode ){
  if( ! ( exprNode instanceof ExprNodeConstantDesc ) ){
    return null;
  }
  ExprNodeConstantDesc constDesc = (ExprNodeConstantDesc)exprNode;
  ObjectInspector objectInspector = constDesc.getWritableObjectInspector();
  if( objectInspector.getCategory() != ObjectInspector.Category.PRIMITIVE ){
    return null;
  }
  return (PrimitiveObjectInspector)objectInspector;
}
 
Example #4
Source File: ExprBuilder.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 4 votes vote down vote up
private ExprBuilder valInternal(TypeInfo ti, Object val) {
  stack.push(new ExprNodeConstantDesc(ti, val));
  return this;
}
 
Example #5
Source File: CompareHiveExpr.java    From multiple-dimension-spread with 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 #6
Source File: BetweenHiveExpr.java    From multiple-dimension-spread with Apache License 2.0 4 votes vote down vote up
@Override
public IExpressionNode getPushDownFilterNode(){
  if( nodeDescList.size() != 4 ){
    return null;
  }
  ExprNodeDesc constNode1 = nodeDescList.get( 0 );
  ExprNodeDesc columnNode = nodeDescList.get( 1 );
  ExprNodeDesc constNode2 = nodeDescList.get( 2 );
  ExprNodeDesc constNode3 = nodeDescList.get( 3 );

  if( ! ( constNode1 instanceof ExprNodeConstantDesc ) || ! ( constNode2 instanceof ExprNodeConstantDesc ) || ! ( constNode3 instanceof ExprNodeConstantDesc ) ){
    return null;
  } 
  ExprNodeConstantDesc booleanNode = (ExprNodeConstantDesc)constNode1;
  ObjectInspector booleanOjectInspector = booleanNode.getWritableObjectInspector();
  if( booleanOjectInspector.getCategory() != ObjectInspector.Category.PRIMITIVE ){
    return null;
  }
  PrimitiveObjectInspector booleanPrimitiveObjectInspector = (PrimitiveObjectInspector)booleanOjectInspector;
  if( booleanPrimitiveObjectInspector.getPrimitiveCategory() != PrimitiveObjectInspector.PrimitiveCategory.BOOLEAN ){
    return null;
  }
  boolean invert = ( (WritableConstantBooleanObjectInspector)booleanPrimitiveObjectInspector ).getWritableConstantValue().get();

  ExprNodeConstantDesc minNode = (ExprNodeConstantDesc)constNode2;
  ExprNodeConstantDesc maxNode = (ExprNodeConstantDesc)constNode3;

  ObjectInspector minOjectInspector = minNode.getWritableObjectInspector();
  ObjectInspector maxOjectInspector = maxNode.getWritableObjectInspector();
  if( minOjectInspector.getCategory() != ObjectInspector.Category.PRIMITIVE || maxOjectInspector.getCategory() != ObjectInspector.Category.PRIMITIVE ){
    return null;
  }
  PrimitiveObjectInspector minPrimitiveObjectInspector = (PrimitiveObjectInspector)minOjectInspector;
  PrimitiveObjectInspector maxPrimitiveObjectInspector = (PrimitiveObjectInspector)maxOjectInspector;
  if( minPrimitiveObjectInspector.getPrimitiveCategory() != maxPrimitiveObjectInspector.getPrimitiveCategory() ){
    return null;
  }

  IExtractNode extractNode = CreateExtractNodeUtil.getExtractNode( columnNode );
  if( extractNode == null ){
    return null;
  }

  return getRangeExecuter( invert , minPrimitiveObjectInspector , maxPrimitiveObjectInspector , extractNode );
}
 
Example #7
Source File: EqualsHiveExpr.java    From multiple-dimension-spread with 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 );
}