/* * Parse the user-data supplied by the HiveFragmenter from InputData. Based on the * user-data construct the partition fields and the InputFormat for current split */ private InputFormat<?, ?> createInputFormat(InputData input) throws Exception { String userData = new String(input.getFragmentUserData()); String[] toks = userData.split(HiveDataFragmenter.HIVE_UD_DELIM); initPartitionFields(toks[3]); filterInFragmenter = new Boolean(toks[4]); return HiveDataFragmenter.makeInputFormat(toks[0] /* inputFormat name */, jobConf); }
/* * We are testing one filter against all the partition fields. * The filter has the form "fieldA = valueA". * The partitions have the form partitionOne=valueOne/partitionTwo=ValueTwo/partitionThree=valueThree * 1. For a filter to match one of the partitions, lets say partitionA for example, we need: * fieldA = partittionOne and valueA = valueOne. If this condition occurs, we return true. * 2. If fieldA does not match any one of the partition fields we also return true, it means we ignore this filter * because it is not on a partition field. * 3. If fieldA = partittionOne and valueA != valueOne, then we return false. */ private boolean testOneFilter( List<HivePartition> partitionFields, Object filter, InputData input) { // Let's look first at the filter FilterParser.BasicFilter bFilter = (FilterParser.BasicFilter) filter; boolean isFilterOperationEqual = (bFilter.getOperation() == FilterParser.Operation.HDOP_EQ); if (!isFilterOperationEqual) /* in case this is not an "equality filter" we ignore it here - in partition filtering */ { return true; } int filterColumnIndex = bFilter.getColumn().index(); String filterValue = bFilter.getConstant().constant().toString(); ColumnDescriptor filterColumn = input.getColumn(filterColumnIndex); String filterColumnName = filterColumn.columnName(); for (HivePartition partition : partitionFields) { if (filterColumnName.equals(partition.name)) { /* the filter field matches a partition field, but the values do not match */ return filterValue.equals(partition.val); } } /* filter field did not match any partition field, so we ignore this filter and hence return true */ return true; }