本文整理汇总了Java中org.apache.pig.data.DataType.compare方法的典型用法代码示例。如果您正苦于以下问题:Java DataType.compare方法的具体用法?Java DataType.compare怎么用?Java DataType.compare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.pig.data.DataType
的用法示例。
在下文中一共展示了DataType.compare方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compareTuple
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
private int compareTuple(Tuple t1, Tuple t2) {
int sz1 = t1.size();
int sz2 = t2.size();
if (sz2 < sz1) {
return 1;
} else if (sz2 > sz1) {
return -1;
} else {
for (int i = 0; i < sz1; i++) {
try {
int c = DataType.compare(t1.get(i), t2.get(i));
if (c != 0) {
if (!mWholeTuple && !mAsc[i])
c *= -1;
else if (mWholeTuple && !mAsc[0])
c *= -1;
return c;
}
} catch (ExecException e) {
throw new RuntimeException("Unable to compare tuples", e);
}
}
return 0;
}
}
示例2: exec
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public T exec(Tuple input) throws IOException {
// System.err.println("FINAL: " + input);
Object ret = null;
// Cycle through.
for (Tuple outerTuple : (DataBag) input.get(0)) {
for (Tuple tup : (DataBag) outerTuple.get(0)) {
// System.err.println("OP cur: " + ret + " check: " + tup);
if (0 <= (Long) tup.get(1)) {
if (ret == null) {
ret = tup.get(0);
} else {
int cmp = DataType.compare(ret, tup.get(0));
if ((runMin && cmp > 0) || (!runMin && cmp < 0)) {
ret = tup.get(0);
}
}
}
}
}
return (T) ret;
}
示例3: compare
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
@Override
public int compare(Tuple o1, Tuple o2) {
if (o1 == null)
return -1;
if (o2 == null)
return 1;
try {
Object field1 = o1.get(fieldNum);
Object field2 = o2.get(fieldNum);
if (!typeFound) {
datatype = DataType.findType(field1);
if(datatype != DataType.NULL) {
typeFound = true;
}
}
return DataType.compare(field1, field2, datatype, datatype);
} catch (ExecException e) {
throw new RuntimeException("Error while comparing o1:" + o1
+ " and o2:" + o2, e);
}
}
示例4: compare
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
public int compare(Object o1, Object o2) {
NullableBytesWritable nbw1 = (NullableBytesWritable)o1;
NullableBytesWritable nbw2 = (NullableBytesWritable)o2;
int rc = 0;
// If either are null, handle differently.
if (!nbw1.isNull() && !nbw2.isNull()) {
rc = DataType.compare(nbw1.getValueAsPigType(), nbw2.getValueAsPigType());
} else {
// For sorting purposes two nulls are equal.
if (nbw1.isNull() && nbw2.isNull()) rc = 0;
else if (nbw1.isNull()) rc = -1;
else rc = 1;
}
if (!mAsc[0]) rc *= -1;
return rc;
}
示例5: compare
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
@Override
public int compare(Tuple o1, Tuple o2) {
if (o1 == null)
return -1;
if (o2 == null)
return 1;
try {
Object field1 = o1.get(fieldNum);
Object field2 = o2.get(fieldNum);
if (!typeFound) {
datatype = DataType.findType(field1);
typeFound = true;
}
return DataType.compare(field1, field2, datatype, datatype);
} catch (ExecException e) {
throw new RuntimeException("Error while comparing o1:" + o1
+ " and o2:" + o2, e);
}
}
示例6: compare
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
@Override
public int compare(Tuple o1, Tuple o2) {
int ret = 0;
if (o1 == null) {
ret = -1;
} else if (o2 == null) {
ret = 1;
} else {
try {
Object field1 = o1.get(fieldNum);
Object field2 = o2.get(fieldNum);
if (!typeFound) {
datatype = DataType.findType(field1);
if(datatype != DataType.NULL) {
typeFound = true;
}
}
ret = DataType.compare(field1, field2, datatype, datatype);
} catch (ExecException e) {
throw new RuntimeException("Error while comparing o1:" + o1
+ " and o2:" + o2, e);
}
}
return isDescOrder ? ret : ret * -1;
}
示例7: hasSameKey
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
private boolean hasSameKey(Tuple t1, Tuple t2) {
// Have to break the tuple down and compare it field to field.
int sz1 = t1 == null ? 0 : t1.size();
int sz2 = t2 == null ? 0 : t2.size();
if (sz2 != sz1) {
return false;
}
for (int i = 0; i < sz1 - 2; i++) {
try {
int c = DataType.compare(t1.get(i), t2.get(i));
if (c != 0) {
return false;
}
} catch (ExecException e) {
throw new RuntimeException("Unable to compare tuples", e);
}
}
return true;
}
示例8: compareTo
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
/**
* Implementation is copied from DefaultTuple implementation in pig.
*
* @param obj the other object to be compared
* @return -1 if the other is less, 0 if equal or 1 if the other is greater to this object
*/
@Override
public int compareTo(Object obj)
{
if (obj instanceof Tuple)
{
Tuple other = (Tuple) obj;
int otherSize = other.size();
if (otherSize < nColumns) return 1;
else if (otherSize > nColumns) return -1;
else
{
for (int i = 0; i < nColumns; i++)
{
try
{
int c = DataType.compare(get(i), other.get(i));
if (c != 0) return c;
}
catch (ExecException e)
{
throw new RuntimeException("Unable to compare tuples", e);
}
}
return 0;
}
}
else
{
return DataType.compare(this, obj);
}
}
示例9: compare
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public int compare(Tuple t1, Tuple t2) {
switch (mState) {
case ALL_ASC:
return t1.compareTo(t2);
case ALL_DESC:
return t2.compareTo(t1);
case MIXED:
// Have to break the tuple down and compare it field to field.
int sz1 = t1.size();
int sz2 = t2.size();
if (sz2 < sz1) {
return 1;
} else if (sz2 > sz1) {
return -1;
} else {
for (int i = 0; i < sz1; i++) {
try {
int c = DataType.compare(t1.get(i), t2.get(i));
if (c != 0) {
if (!mAsc[i]) c *= -1;
return c;
}
} catch (ExecException e) {
throw new RuntimeException("Unable to compare tuples", e);
}
}
return 0;
}
}
return -1; // keep the compiler happy
}
示例10: poSortDescInt
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
public void poSortDescInt(DataBag input) throws ExecException {
List<PhysicalPlan> sortPlans = new LinkedList<PhysicalPlan>();
POProject pr1 = new POProject(new OperatorKey("", r.nextLong()), -1, 1);
pr1.setResultType(DataType.INTEGER);
PhysicalPlan expPlan = new PhysicalPlan();
expPlan.add(pr1);
sortPlans.add(expPlan);
List<Boolean> mAscCols = new LinkedList<Boolean>();
mAscCols.add(false);
PORead read = new PORead(new OperatorKey("", r.nextLong()), input);
List<PhysicalOperator> inputs = new LinkedList<PhysicalOperator>();
inputs.add(read);
POSort sort = new POSort(new OperatorKey("", r.nextLong()), -1, inputs,
sortPlans, mAscCols, null);
Tuple t = null;
Result res1 = sort.getNextTuple();
// System.out.println(res1.result);
Result res2 = sort.getNextTuple();
while (res2.returnStatus != POStatus.STATUS_EOP) {
Object i1 = ((Tuple) res1.result).get(1);
Object i2 = ((Tuple) res2.result).get(1);
int i = DataType.compare(i1, i2);
assertEquals(true, (i >= 0));
// System.out.println(res2.result);
res1 = res2;
res2 = sort.getNextTuple();
}
}
示例11: compare
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
@Override
public int compare(Tuple o1, Tuple o2) {
int count = 0;
int ret = 0;
if(sortPlans == null || sortPlans.size() == 0) {
return 0;
}
for(PhysicalPlan plan : sortPlans) {
try {
plan.attachInput(o1);
Result res1 = getResult(plan, ExprOutputTypes.get(count));
plan.attachInput(o2);
Result res2 = getResult(plan, ExprOutputTypes.get(count));
if(res1.returnStatus != POStatus.STATUS_OK || res2.returnStatus != POStatus.STATUS_OK) {
log.error("Error processing the input in the expression plan : " + plan.toString());
} else {
if(mAscCols.get(count++)) {
ret = DataType.compare(res1.result, res2.result);
// If they are not equal, return
// Otherwise, keep comparing the next one
if (ret != 0) {
return ret ;
}
}
else {
ret = DataType.compare(res2.result, res1.result);
if (ret != 0) {
return ret ;
}
}
}
} catch (ExecException e) {
log.error("Invalid result while executing the expression plan : " + plan.toString() + "\n" + e.getMessage());
}
}
return ret;
}
示例12: compareTuple
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
private int compareTuple(Tuple t1, Tuple t2) {
int sz1 = t1.size();
int sz2 = t2.size();
if (sz2 < sz1) {
return 1;
} else if (sz2 > sz1) {
return -1;
} else {
for (int i = 0; i < sz1; i++) {
try {
Object o1 = t1.get(i);
Object o2 = t2.get(i);
if (o1==null || o2==null)
mHasNullField = true;
int c = DataType.compare(o1, o2);
if (c != 0) {
if (!mWholeTuple && !mAsc[i])
c *= -1;
else if (mWholeTuple && !mAsc[0])
c *= -1;
return c;
}
} catch (ExecException e) {
throw new RuntimeException("Unable to compare tuples", e);
}
}
return 0;
}
}
示例13: poSortAscString
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
public void poSortAscString(DataBag input) throws ExecException {
List<PhysicalPlan> sortPlans = new LinkedList<PhysicalPlan>();
POProject pr1 = new POProject(new OperatorKey("", r.nextLong()), -1, 0);
pr1.setResultType(DataType.CHARARRAY);
PhysicalPlan expPlan = new PhysicalPlan();
expPlan.add(pr1);
sortPlans.add(expPlan);
List<Boolean> mAscCols = new LinkedList<Boolean>();
mAscCols.add(true);
PORead read = new PORead(new OperatorKey("", r.nextLong()), input);
List<PhysicalOperator> inputs = new LinkedList<PhysicalOperator>();
inputs.add(read);
POSort sort = new POSort(new OperatorKey("", r.nextLong()), -1, inputs,
sortPlans, mAscCols, null);
//verify
Tuple t = null;
Result res1 = sort.getNextTuple();
Result res2 = sort.getNextTuple();
while (res2.returnStatus != POStatus.STATUS_EOP) {
Object i1 = ((Tuple) res1.result).get(0);
Object i2 = ((Tuple) res2.result).get(0);
//System.out.println("i1: " + i1.toString() + " i2: " + i2.toString());
int i = DataType.compare(i1, i2);
System.out.println("RESULT2=i : " + res2.result + " i = " + i);
assertEquals(true, (i <= 0));
res1 = res2;
res2 = sort.getNextTuple();
}
}
示例14: poSortDescString
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
public void poSortDescString(DataBag input) throws ExecException {
List<PhysicalPlan> sortPlans = new LinkedList<PhysicalPlan>();
POProject pr1 = new POProject(new OperatorKey("", r.nextLong()), -1, 0);
pr1.setResultType(DataType.CHARARRAY);
PhysicalPlan expPlan = new PhysicalPlan();
expPlan.add(pr1);
sortPlans.add(expPlan);
List<Boolean> mAscCols = new LinkedList<Boolean>();
mAscCols.add(false);
PORead read = new PORead(new OperatorKey("", r.nextLong()), input);
List<PhysicalOperator> inputs = new LinkedList<PhysicalOperator>();
inputs.add(read);
POSort sort = new POSort(new OperatorKey("", r.nextLong()), -1, inputs,
sortPlans, mAscCols, null);
Tuple t = null;
Result res1 = sort.getNextTuple();
// System.out.println(res1.result);
Result res2 = sort.getNextTuple();
while (res2.returnStatus != POStatus.STATUS_EOP) {
Object i1 = ((Tuple) res1.result).get(0);
Object i2 = ((Tuple) res2.result).get(0);
int i = DataType.compare(i1, i2);
// System.out.println(res2.result + " i = " + i);
assertEquals(true, (i >= 0));
res1 = res2;
res2 = sort.getNextTuple();
}
}
示例15: poSortAscInt
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
public void poSortAscInt( DataBag input) throws ExecException {
List<PhysicalPlan> sortPlans = new LinkedList<PhysicalPlan>();
POProject pr1 = new POProject(new OperatorKey("", r.nextLong()), -1, 1);
pr1.setResultType(DataType.INTEGER);
PhysicalPlan expPlan = new PhysicalPlan();
expPlan.add(pr1);
sortPlans.add(expPlan);
List<Boolean> mAscCols = new LinkedList<Boolean>();
mAscCols.add(true);
PORead read = new PORead(new OperatorKey("", r.nextLong()), input);
List<PhysicalOperator> inputs = new LinkedList<PhysicalOperator>();
inputs.add(read);
POSort sort = new POSort(new OperatorKey("", r.nextLong()), -1, inputs,
sortPlans, mAscCols, null);
Tuple t = null;
Result res1 = sort.getNextTuple();
// System.out.println(res1.result);
Result res2 = sort.getNextTuple();
while (res2.returnStatus != POStatus.STATUS_EOP) {
Object i1 = ((Tuple) res1.result).get(1);
Object i2 = ((Tuple) res2.result).get(1);
int i = DataType.compare(i1, i2);
assertEquals(true, (i <= 0));
// System.out.println(res2.result);
res1 = res2;
res2 = sort.getNextTuple();
}
}