本文整理汇总了Java中org.apache.pig.data.DataType.toDouble方法的典型用法代码示例。如果您正苦于以下问题:Java DataType.toDouble方法的具体用法?Java DataType.toDouble怎么用?Java DataType.toDouble使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.pig.data.DataType
的用法示例。
在下文中一共展示了DataType.toDouble方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exec
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
/**
* java level API
* @param input expects a single numeric value
* @return output returns a single numeric value,
* the closest long to the argument
*/
@Override
public Long exec(Tuple input) throws IOException {
if (input == null || input.size() == 0 || input.get(0) == null)
return null;
try{
Double d = DataType.toDouble(input.get(0));
return Math.round(d);
} catch (NumberFormatException nfe){
System.err.println("Failed to process input; error - " + nfe.getMessage());
return null;
} catch (Exception e){
throw new IOException("Caught exception processing input row ", e);
}
}
示例2: exec
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
/**
* java level API
* @param input expects a single numeric value
* @param output returns a single numeric value, nextup value of the argument
*/
public Double exec(Tuple input) throws IOException {
if (input == null || input.size() == 0 || input.get(0) == null)
return null;
Double d;
try{
d = DataType.toDouble(input.get(0));
} catch (NumberFormatException nfe){
System.err.println("Failed to process input; error - " + nfe.getMessage());
return null;
} catch (Exception e){
throw new IOException("Caught exception processing input row ", e);
}
return Math.nextUp(d);
}
示例3: exec
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
/**
* java level API
* @param input expects a numeric value to round, a number of digits to keep, and an optional rounding mode.
* @return output returns a single numeric value, the number with only those digits retained
*/
@Override
public Double exec(Tuple input) throws IOException {
if (input == null || input.size() < 2)
return null;
try {
Double num = DataType.toDouble(input.get(0));
Integer digits = DataType.toInteger(input.get(1));
RoundingMode mode = (input.size() >= 3) ?
RoundingMode.valueOf(DataType.toInteger(input.get(2))) : RoundingMode.HALF_EVEN;
if (num == null) return null;
BigDecimal bdnum = BigDecimal.valueOf(num);
bdnum = bdnum.setScale(digits, mode);
return bdnum.doubleValue();
} catch (NumberFormatException nfe){
System.err.println("Failed to process input; error - " + nfe.getMessage());
return null;
} catch (Exception e){
throw new IOException("Caught exception processing input row ", e);
}
}
示例4: exec
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
/**
* java level API
* @param input expects a single numeric value
* @param output returns a single numeric value, absolute value of the argument
*/
public Double exec(Tuple input) throws IOException {
if (input == null || input.size() == 0)
return null;
Double d;
try{
d = DataType.toDouble(input.get(0));
} catch (NumberFormatException nfe){
System.err.println("Failed to process input; error - " + nfe.getMessage());
return null;
} catch (Exception e){
throw new IOException("Caught exception processing input row ", e);
}
return Math.abs(d);
}
示例5: exec
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
/**
* java level API
* @param input expects a tuple containing two numeric DataAtom value
* @param output returns a single numeric DataAtom value, which is
* first floating-point argument with the sign of the second
* floating-point argument.
*/
@Override
public Double exec(Tuple input) throws IOException {
if (input == null || input.size() < 2)
return null;
try{
double first = DataType.toDouble(input.get(0));
double second = DataType.toDouble(input.get(1));
return Math.copySign(first, second);
} catch (NumberFormatException nfe){
System.err.println("Failed to process input; error - " + nfe.getMessage());
return null;
} catch(Exception e){
throw new IOException("Caught exception processing input row ", e);
}
}
示例6: exec
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
/**
* java level API
* @param input expects a tuple containing two numeric DataAtom value
* @param output returns a single numeric value, which is
* the the larger value among the two.
*/
@Override
public Double exec(Tuple input) throws IOException {
if (input == null || input.size() < 2)
return null;
try{
Double first = DataType.toDouble(input.get(0));
Double second = DataType.toDouble(input.get(1));
if (first==null)
return second;
if (second==null)
return first;
return Math.max(first, second);
} catch (NumberFormatException nfe){
System.err.println("Failed to process input; error - " + nfe.getMessage());
return null;
} catch(Exception e){
throw new IOException("Caught exception in MAX.Initial", e);
}
}
示例7: exec
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
/**
* java level API
* @param input expects a tuple containing two numeric DataAtom value
* @param output returns a single numeric value, which is
* the the smaller value among the two.
*/
@Override
public Double exec(Tuple input) throws IOException {
if (input == null || input.size() < 2)
return null;
try{
Double first = DataType.toDouble(input.get(0));
Double second = DataType.toDouble(input.get(1));
return Math.min(first, second);
} catch (NumberFormatException nfe){
System.err.println("Failed to process input; error - " + nfe.getMessage());
return null;
} catch(Exception e){
throw new IOException("Caught exception in MIN.Initial", e);
}
}
示例8: exec
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
/**
* java level API
* @param input expects a single numeric value
* @return output returns a single numeric value, absolute value of the argument
*/
public Double exec(Tuple input) throws IOException {
if (input == null || input.size() == 0 || input.get(0) == null)
return null;
Double d;
try{
d = DataType.toDouble(input.get(0));
} catch (NumberFormatException nfe){
System.err.println("Failed to process input; error - " + nfe.getMessage());
return null;
} catch (Exception e){
throw new IOException("Caught exception processing input row ", e);
}
return Math.abs(d);
}
示例9: exec
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
/**
* java level API
* @param input expects a tuple containing two numeric DataAtom value
* @param output returns a single numeric DataAtom value, which is
* the floating-point number adjacent to the first argument in the
* direction of the second argument.
*/
@Override
public Double exec(Tuple input) throws IOException {
if (input == null || input.size() < 2) {
return null;
}
if (input.get(0) == null || input.get(1) == null) {
return null;
}
try{
double first = DataType.toDouble(input.get(0));
double second = DataType.toDouble(input.get(1));
return Math.nextAfter(first, second);
} catch (NumberFormatException nfe){
System.err.println("Failed to process input; error - " + nfe.getMessage());
return null;
} catch(Exception e){
throw new IOException("Caught exception in nextAfter", e);
}
}
示例10: testMultiply
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
@Test
public void testMultiply() throws Throwable {
File tmpFile = File.createTempFile("test", "txt");
for (int i = 0; i < nullFlags.length; i++) {
System.err.println("Testing with nulls: " + nullFlags[i]);
PrintStream ps = new PrintStream(new FileOutputStream(tmpFile));
generateInput(ps, nullFlags[i]);
String query = "A = foreach (load '"
+ Util.encodeEscape(Util.generateURI(tmpFile.toString(), pig.getPigContext()))
+ "' using " + PigStorage.class.getName()
+ "(':')) generate $0, $0 * $1, $1 ;";
log.info(query);
pig.registerQuery(query);
Iterator<Tuple> it = pig.openIterator("A");
tmpFile.delete();
while(it.hasNext()) {
Tuple t = it.next();
Double first = (t.get(0) == null ? null :DataType.toDouble(t.get(0)));
Double second = (t.get(1) == null ? null :DataType.toDouble(t.get(1)));
Double third = (t.get(2) == null ? null :DataType.toDouble(t.get(2)));
if(first != null && third != null) {
assertEquals(Double.valueOf(first * first), second);
} else {
assertNull(second);
}
}
}
}
示例11: testSubtract
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
@Test
public void testSubtract() throws Throwable {
File tmpFile = File.createTempFile("test", "txt");
for (int i = 0; i < nullFlags.length; i++) {
System.err.println("Testing with nulls: " + nullFlags[i]);
PrintStream ps = new PrintStream(new FileOutputStream(tmpFile));
generateInput(ps, nullFlags[i]);
String query = "A = foreach (load '"
+ Util.encodeEscape(Util.generateURI(tmpFile.toString(), pig.getPigContext()))
+ "' using " + PigStorage.class.getName()
+ "(':')) generate $0, $0 - $1, $1 ;";
log.info(query);
pig.registerQuery(query);
Iterator<Tuple> it = pig.openIterator("A");
tmpFile.delete();
while(it.hasNext()) {
Tuple t = it.next();
Double first = (t.get(0) == null ? null :DataType.toDouble(t.get(0)));
Double second = (t.get(1) == null ? null :DataType.toDouble(t.get(1)));
Double third = (t.get(2) == null ? null :DataType.toDouble(t.get(2)));
if(first != null && third != null) {
assertEquals(Double.valueOf(0.0), second);
} else {
assertNull(second);
}
}
}
}
示例12: exec
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
/**
* java level API
* @param input expects a single numeric value
* @param output returns a single numeric value, unbiased
* exponent used in the representation of a double
*/
public Integer exec(Tuple input) throws IOException {
if (input == null || input.size() == 0 || input.get(0) == null)
return null;
try {
Double d = DataType.toDouble(input.get(0));
return Math.getExponent(d);
} catch (NumberFormatException nfe){
System.err.println("Failed to process input; error - " + nfe.getMessage());
return null;
} catch (Exception e){
throw new IOException("Caught exception processing input row ", e);
}
}
示例13: testAdd
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
@Test
public void testAdd() throws Throwable {
File tmpFile = File.createTempFile("test", "txt");
for (int i = 0; i < nullFlags.length; i++) {
System.err.println("Testing with nulls: " + nullFlags[i]);
PrintStream ps = new PrintStream(new FileOutputStream(tmpFile));
generateInput(ps, nullFlags[i]);
String query = "A = foreach (load '"
+ Util.generateURI(tmpFile.toString(), pig.getPigContext())
+ "' using " + PigStorage.class.getName()
+ "(':')) generate $0, $0 + $1, $1;";
log.info(query);
pig.registerQuery(query);
Iterator<Tuple> it = pig.openIterator("A");
tmpFile.delete();
while(it.hasNext()) {
Tuple t = it.next();
Double first = (t.get(0) == null ? null :DataType.toDouble(t.get(0)));
Double second = (t.get(1) == null ? null :DataType.toDouble(t.get(1)));
Double third = (t.get(2) == null ? null :DataType.toDouble(t.get(2)));
if(first != null && third != null) {
assertEquals(Double.valueOf(first + first), second);
} else {
assertNull(second);
}
}
}
}
示例14: testSubtract
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
@Test
public void testSubtract() throws Throwable {
File tmpFile = File.createTempFile("test", "txt");
for (int i = 0; i < nullFlags.length; i++) {
System.err.println("Testing with nulls: " + nullFlags[i]);
PrintStream ps = new PrintStream(new FileOutputStream(tmpFile));
generateInput(ps, nullFlags[i]);
String query = "A = foreach (load '"
+ Util.generateURI(tmpFile.toString(), pig.getPigContext())
+ "' using " + PigStorage.class.getName()
+ "(':')) generate $0, $0 - $1, $1 ;";
log.info(query);
pig.registerQuery(query);
Iterator<Tuple> it = pig.openIterator("A");
tmpFile.delete();
while(it.hasNext()) {
Tuple t = it.next();
Double first = (t.get(0) == null ? null :DataType.toDouble(t.get(0)));
Double second = (t.get(1) == null ? null :DataType.toDouble(t.get(1)));
Double third = (t.get(2) == null ? null :DataType.toDouble(t.get(2)));
if(first != null && third != null) {
assertEquals(Double.valueOf(0.0), second);
} else {
assertNull(second);
}
}
}
}
示例15: exec
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
/**
* java level API
* @param input expects a single numeric value
* @param output returns a single numeric value,
* the size of an ulp of the argument.
*/
public Double exec(Tuple input) throws IOException {
if (input == null || input.size() == 0 || input.get(0) == null)
return null;
try{
Double d = DataType.toDouble(input.get(0));
return Math.ulp(d);
}catch(NumberFormatException nfe){
System.err.println("Failed to process input; error - " + nfe.getMessage());
return null;
} catch(Exception e){
throw new IOException("Caught exception in ULP.", e);
}
}