diff --git ql/src/java/org/apache/hadoop/hive/ql/optimizer/pcr/PcrExprProcFactory.java ql/src/java/org/apache/hadoop/hive/ql/optimizer/pcr/PcrExprProcFactory.java index bd0e8c3..e46e144 100644 --- ql/src/java/org/apache/hadoop/hive/ql/optimizer/pcr/PcrExprProcFactory.java +++ ql/src/java/org/apache/hadoop/hive/ql/optimizer/pcr/PcrExprProcFactory.java @@ -62,7 +62,6 @@ static Object evalExprWithPart(ExprNodeDesc expr, Partition p, List partSpec = p.getSpec(); try { rowObjectInspector = (StructObjectInspector) tbl @@ -72,7 +71,7 @@ static Object evalExprWithPart(ExprNodeDesc expr, Partition p, List partSpec, List vcs, + Partition p, List vcs, StructObjectInspector rowObjectInspector) throws HiveException { + LinkedHashMap partSpec = p.getSpec(); + Properties partProps = p.getSchema(); + String pcolTypes = partProps.getProperty(hive_metastoreConstants.META_TABLE_PARTITION_COLUMN_TYPES); + String[] partKeyTypes = pcolTypes.trim().split(":"); + + if (partSpec.size() != partKeyTypes.length) { + throw new HiveException("Internal error : Partition Spec size, " + partProps.size() + + " doesn't match partition key definition size, " + partKeyTypes.length); + } boolean hasVC = vcs != null && !vcs.isEmpty(); Object[] rowWithPart = new Object[hasVC ? 3 : 2]; // Create the row object ArrayList partNames = new ArrayList(); - ArrayList partValues = new ArrayList(); + ArrayList partValues = new ArrayList(); ArrayList partObjectInspectors = new ArrayList(); + int i=0; for (Map.Entry entry : partSpec.entrySet()) { partNames.add(entry.getKey()); - partValues.add(entry.getValue()); - partObjectInspectors - .add(PrimitiveObjectInspectorFactory.javaStringObjectInspector); + ObjectInspector oi = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector + (TypeInfoFactory.getPrimitiveTypeInfo(partKeyTypes[i++])); + partValues.add(ObjectInspectorConverters.getConverter( + PrimitiveObjectInspectorFactory.javaStringObjectInspector, oi) + .convert(entry.getValue())); + partObjectInspectors.add(oi); } StructObjectInspector partObjectInspector = ObjectInspectorFactory .getStandardStructObjectInspector(partNames, partObjectInspectors); diff --git ql/src/test/queries/clientpositive/pcr.q ql/src/test/queries/clientpositive/pcr.q index a7199b3..3be0ff2 100644 --- ql/src/test/queries/clientpositive/pcr.q +++ ql/src/test/queries/clientpositive/pcr.q @@ -112,7 +112,7 @@ insert overwrite table pcr_foo partition (ds=5) select * from src where key < 10 insert overwrite table pcr_foo partition (ds=7) select * from src where key < 10 order by key; -- the condition is 'true' for all the 3 partitions (ds=3,5,7): -select key, value, ds from pcr_foo where (ds % 2.0 == 1); +select key, value, ds from pcr_foo where (ds % 2 == 1); -- the condition is 'true' for partitions (ds=3,5) but 'false' of partition ds=7: select key, value, ds from pcr_foo where (ds / 3 < 2); diff --git ql/src/test/results/clientpositive/pcr.q.out ql/src/test/results/clientpositive/pcr.q.out index bf5bcce..44c8856 100644 --- ql/src/test/results/clientpositive/pcr.q.out +++ ql/src/test/results/clientpositive/pcr.q.out @@ -6267,7 +6267,7 @@ POSTHOOK: Lineage: pcr_t3.key SIMPLE [(pcr_t1)pcr_t1.FieldSchema(name:key, type: POSTHOOK: Lineage: pcr_t3.value SIMPLE [(pcr_t1)pcr_t1.FieldSchema(name:value, type:string, comment:null), ] POSTHOOK: Lineage: pcr_t3.value SIMPLE [(pcr_t1)pcr_t1.FieldSchema(name:value, type:string, comment:null), ] PREHOOK: query: -- the condition is 'true' for all the 3 partitions (ds=3,5,7): -select key, value, ds from pcr_foo where (ds % 2.0 == 1) +select key, value, ds from pcr_foo where (ds % 2 == 1) PREHOOK: type: QUERY PREHOOK: Input: default@pcr_foo PREHOOK: Input: default@pcr_foo@ds=3 @@ -6275,7 +6275,7 @@ PREHOOK: Input: default@pcr_foo@ds=5 PREHOOK: Input: default@pcr_foo@ds=7 #### A masked pattern was here #### POSTHOOK: query: -- the condition is 'true' for all the 3 partitions (ds=3,5,7): -select key, value, ds from pcr_foo where (ds % 2.0 == 1) +select key, value, ds from pcr_foo where (ds % 2 == 1) POSTHOOK: type: QUERY POSTHOOK: Input: default@pcr_foo POSTHOOK: Input: default@pcr_foo@ds=3