All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jp.co.yahoo.yosegi.hive.pushdown.BetweenHiveExpr Maven / Gradle / Ivy

The newest version!
/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 

* http://www.apache.org/licenses/LICENSE-2.0 *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package jp.co.yahoo.yosegi.hive.pushdown; import jp.co.yahoo.yosegi.message.objects.ByteObj; import jp.co.yahoo.yosegi.message.objects.DoubleObj; import jp.co.yahoo.yosegi.message.objects.FloatObj; import jp.co.yahoo.yosegi.message.objects.IntegerObj; import jp.co.yahoo.yosegi.message.objects.LongObj; import jp.co.yahoo.yosegi.message.objects.PrimitiveObject; import jp.co.yahoo.yosegi.message.objects.ShortObj; import jp.co.yahoo.yosegi.spread.column.filter.IFilter; import jp.co.yahoo.yosegi.spread.column.filter.NumberRangeFilter; import jp.co.yahoo.yosegi.spread.column.filter.RangeStringCompareFilter; import jp.co.yahoo.yosegi.spread.expression.ExecuterNode; import jp.co.yahoo.yosegi.spread.expression.IExpressionNode; import jp.co.yahoo.yosegi.spread.expression.IExtractNode; import org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc; import org.apache.hadoop.hive.ql.plan.ExprNodeDesc; import org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc; import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantBooleanObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantByteObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantDoubleObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantFloatObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantIntObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantLongObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantShortObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantStringObjectInspector; import java.util.List; public class BetweenHiveExpr implements IHiveExprNode { private final List nodeDescList; public BetweenHiveExpr( final List nodeDescList ) { this.nodeDescList = nodeDescList; } public static IExpressionNode getNumberRangeExecuter( final boolean invert , final PrimitiveObject minObj , final PrimitiveObject maxObj , final IExtractNode targetColumn ) { return new ExecuterNode( targetColumn , new NumberRangeFilter( invert , minObj , true , maxObj , true ) ); } /** * Create Yosegi filtering. */ 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; } } @Override public void addChildNode( final ExprNodeGenericFuncDesc exprNodeDesc ) { throw new UnsupportedOperationException( "IHiveExprNode node can not have child node." ); } @Override public IExpressionNode getPushDownFilterNode() { if ( nodeDescList.size() != 4 ) { return null; } ExprNodeDesc constNode1 = nodeDescList.get( 0 ); 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; } 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; } ExprNodeDesc columnNode = nodeDescList.get( 1 ); IExtractNode extractNode = CreateExtractNodeUtil.getExtractNode( columnNode ); if ( extractNode == null ) { return null; } boolean invert = ( (WritableConstantBooleanObjectInspector)booleanPrimitiveObjectInspector ) .getWritableConstantValue().get(); return getRangeExecuter( invert , minPrimitiveObjectInspector , maxPrimitiveObjectInspector , extractNode ); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy