org.apache.pig.data.Tuple.isNull()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(5.2k)|赞(0)|评价(0)|浏览(90)

本文整理了Java中org.apache.pig.data.Tuple.isNull()方法的一些代码示例,展示了Tuple.isNull()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tuple.isNull()方法的具体详情如下:
包路径:org.apache.pig.data.Tuple
类名称:Tuple
方法名:isNull

Tuple.isNull介绍

[英]Find out if a given field is null.
[中]找出给定字段是否为空。

代码示例

代码示例来源:origin: org.apache.pig/pig

@Override
public boolean isNull(int fieldNum) throws ExecException {
  return t.isNull(fieldNum);
}

代码示例来源:origin: org.apache.pig/pig

protected boolean isKeyNull(Object key) throws ExecException {
  if (key == null) return true;
  if (key instanceof Tuple) {
    Tuple t = (Tuple)key;
    for (int i=0; i<t.size(); i++) {
      if (t.isNull(i)) return true;
    }
  }
  return false;
}

代码示例来源:origin: org.apache.pig/pig

protected int compareNull(boolean usNull, Tuple t, int pos) {
  boolean themNull;
  try {
    themNull = t.isNull(pos);
  } catch (ExecException e) {
    throw new RuntimeException("Unable to check if position " + pos + " is null in Tuple: " + t, e);
  }
  return compareNull(usNull, themNull);
}

代码示例来源:origin: com.twitter.elephantbird/elephant-bird-pig

@Override
public boolean isNull(int idx) throws ExecException {
 get(idx);
 return realTuple.isNull(idx);
}

代码示例来源:origin: org.apache.pig/pig

private boolean isAppendedFieldNull(int i) throws ExecException {
  return isAppendedFieldsNull() || appendedFields.isNull(i);
}

代码示例来源:origin: thedatachef/varaha

public boolean hasNext() {
  if (tupleItr.hasNext()) {
    Tuple t = tupleItr.next();
    try {
      if (!t.isNull(0) && !t.isNull(1)) {
        currentId = t.get(0).toString();
        currentText = t.get(1).toString();
        if (currentId.isEmpty() || currentText.isEmpty()) {
          return false;
        } else {
          return true;
        }   
      }
    } catch (ExecException e) {
      throw new RuntimeException(e);
    }
  }
  return false;
}

代码示例来源:origin: thedatachef/varaha

/**
  Returns the scalar inner product of this and the other term vector by
  multiplying each entry for the same term.
  <p>
  There are undoubtedly ways to optimize this. Please, enlighten me.
  @param other: Another term vector
  @return the dot product
*/
public Double dotProduct(TermVector other) throws ExecException {
  Double result = 0.0;
  for (Tuple x_i : this) {
    for (Tuple y_i : other) {
      if ( !(x_i.isNull(0) || x_i.isNull(1) || y_i.isNull(0) || y_i.isNull(1)) ) {
        if (x_i.get(0).toString().equals(y_i.get(0).toString())) {
          result += (Double)x_i.get(1)*(Double)y_i.get(1);
        }
      }
    }
  }
  return result;
}

代码示例来源:origin: thedatachef/varaha

public Double exec(Tuple input) throws IOException {
  if (input == null || input.size() < 2 || input.isNull(0) || input.isNull(1))
    return null;
  
  TermVector t1 = new TermVector((DataBag)input.get(0));
  TermVector t2 = new TermVector((DataBag)input.get(1));
  
  return t1.cosineSimilarity(t2);
}

代码示例来源:origin: thedatachef/varaha

public DataBag exec(Tuple input) throws IOException {
  if (input == null || input.size() < 1 || input.isNull(0))
    return null;
    DataBag v = (DataBag)t.get(0);
    for (Tuple v_i : v) {
      if (!(v_i.isNull(0) || v_i.isNull(1))) {
        String term = v_i.get(0).toString();
        Object currentValue = termSums.get(term);

代码示例来源:origin: infochimps-labs/wonderdog

/**
  Map a tuple object into a map-writable object for elasticsearch.
 */
@SuppressWarnings("unchecked")
@Override
public void putNext(Tuple t) throws IOException {
  if (!t.isNull(0)) {
    MapWritable record  = new MapWritable();
    String jsonData = t.get(0).toString();
    // parse json data and put into mapwritable record
    try {
      HashMap<String,Object> data = mapper.readValue(jsonData, HashMap.class);
      record = (MapWritable)toWritable(data);
    } catch (JsonParseException e) {
      e.printStackTrace();
    } catch (JsonMappingException e) {
      e.printStackTrace();
    }
    try {
      writer.write(NullWritable.get(), record);
    } catch (InterruptedException e) {
      throw new IOException(e);
    }
  }
}

代码示例来源:origin: infochimps-labs/wonderdog

if (!t.isNull(0)) {                
  String jsonData = t.get(0).toString();

代码示例来源:origin: thedatachef/varaha

public DataBag exec(Tuple input) throws IOException {
    if (input == null || input.size() < 1 || input.isNull(0))
      return null;

    // Output bag
    DataBag bagOfTokens = bagFactory.newDefaultBag();
        
    StringReader textInput = new StringReader(input.get(0).toString());
    PTBTokenizer ptbt = new PTBTokenizer(textInput, new CoreLabelTokenFactory(), "");

    for (CoreLabel label; ptbt.hasNext(); ) {
     label = (CoreLabel)ptbt.next();
     Tuple termText = tupleFactory.newTuple(label.toString());
     bagOfTokens.add(termText);
    }
    
    return bagOfTokens;
  }
}

代码示例来源:origin: thedatachef/varaha

/**
  Uses Lucene's StandardAnalyzer and tuns the tokens through several lucene filters
  - LengthFilter: Filter individual words to be of length > minWordSize
  - ShingleFilter: Converts word stream into n-gram stream
  - PatternReplaceFilter: Removes the 'filler' character that ShingleFilter puts in to
   replace stopwords
 */
public DataBag exec(Tuple input) throws IOException {
  if (input == null || input.size() < 1 || input.isNull(0))
    return null;
  
  TokenStream stream = analyzer.tokenStream(NOFIELD, input.get(0).toString());
  LengthFilter filtered = new LengthFilter(Version.LUCENE_44, stream, minWordSize, Integer.MAX_VALUE); // Let words be long
  DataBag result;
  if (minGramSize == 1 && maxGramSize == 1) {
    result = fillBag(filtered);
  } else {
    ShingleFilter nGramStream = new ShingleFilter(filtered, minGramSize, maxGramSize);        
    nGramStream.setOutputUnigrams(outputUnigrams);                
    PatternReplaceFilter replacer = new PatternReplaceFilter(nGramStream, SHINGLE_FILLER, NOFIELD, true);
    result = fillBag(replacer);
  }
  return result;
}

代码示例来源:origin: thedatachef/varaha

public DataBag exec(Tuple input) throws IOException {
  if (input == null || input.size() < 2 || input.isNull(0) || input.isNull(1))
    return null;

代码示例来源:origin: com.twitter/parquet-pig

assert fields.size() == pigFields.size();
for (int i = 0; i < fields.size(); i++) {
 if (t.isNull(i)) {
  continue;

相关文章