Java Code Examples for org.apache.spark.sql.Row#getLong()

The following examples show how to use org.apache.spark.sql.Row#getLong() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KafkaInput.java    From envelope with Apache License 2.0 6 votes vote down vote up
private Map<TopicPartition, Long> getLastOffsets() throws Exception {
  Map<TopicPartition, Long> offsetRanges = Maps.newHashMap();
  // Create filter for groupid/topic
  for (String topic : topics) {
    StructType filterSchema = DataTypes.createStructType(Lists.newArrayList(
        DataTypes.createStructField("group_id", DataTypes.StringType, false),
        DataTypes.createStructField("topic", DataTypes.StringType, false)));
    Row groupIDTopicFilter = new RowWithSchema(filterSchema, groupID, topic);
    Iterable<Row> filters = Collections.singleton(groupIDTopicFilter);

    // Get results
    RandomOutput output = getOffsetsOutput(config, true);
    Iterable<Row> results = output.getExistingForFilters(filters);

    // Transform results into map
    for (Row result : results) {
      Integer partition = result.getInt(result.fieldIndex("partition"));
      Long offset = result.getLong(result.fieldIndex("offset"));
      TopicPartition topicPartition = new TopicPartition(topic, partition);
      offsetRanges.put(topicPartition, offset);
    }
  }
  
  return offsetRanges;
}
 
Example 2
Source File: JavaUserDefinedUntypedAggregation.java    From incubator-nemo with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the given aggregation buffer `buffer` with new input data from `input`.
 *
 * @param buffer buffer to update.
 * @param input  input to update with.
 */
public void update(final MutableAggregationBuffer buffer, final Row input) {
  if (!input.isNullAt(0)) {
    long updatedSum = buffer.getLong(0) + input.getLong(0);
    long updatedCount = buffer.getLong(1) + 1;
    buffer.update(0, updatedSum);
    buffer.update(1, updatedCount);
  }
}
 
Example 3
Source File: JavaUserDefinedUntypedAggregation.java    From incubator-nemo with Apache License 2.0 5 votes vote down vote up
/**
 * Merges two aggregation buffers and stores the updated buffer values back to `buffer1`.
 *
 * @param buffer1 first buffer.
 * @param buffer2 second buffer.
 */
public void merge(final MutableAggregationBuffer buffer1, final Row buffer2) {
  long mergedSum = buffer1.getLong(0) + buffer2.getLong(0);
  long mergedCount = buffer1.getLong(1) + buffer2.getLong(1);
  buffer1.update(0, mergedSum);
  buffer1.update(1, mergedCount);
}
 
Example 4
Source File: RewriteManifestsAction.java    From iceberg with Apache License 2.0 5 votes vote down vote up
private static ManifestFile writeManifest(
    List<Row> rows, int startIndex, int endIndex, Broadcast<FileIO> io,
    String location, int format, PartitionSpec spec, StructType sparkType) throws IOException {

  String manifestName = "optimized-m-" + UUID.randomUUID();
  Path manifestPath = new Path(location, manifestName);
  OutputFile outputFile = io.value().newOutputFile(FileFormat.AVRO.addExtension(manifestPath.toString()));

  Types.StructType dataFileType = DataFile.getType(spec.partitionType());
  SparkDataFile wrapper = new SparkDataFile(dataFileType, sparkType);

  ManifestWriter writer = ManifestFiles.write(format, spec, outputFile, null);

  try {
    for (int index = startIndex; index < endIndex; index++) {
      Row row = rows.get(index);
      long snapshotId = row.getLong(0);
      long sequenceNumber = row.getLong(1);
      Row file = row.getStruct(2);
      writer.existing(wrapper.wrap(file), snapshotId, sequenceNumber);
    }
  } finally {
    writer.close();
  }

  return writer.toManifestFile();
}
 
Example 5
Source File: TestHelpers.java    From iceberg with Apache License 2.0 5 votes vote down vote up
private static Object getPrimitiveValue(Row row, int ord, Type type) {
  if (row.isNullAt(ord)) {
    return null;
  }
  switch (type.typeId()) {
    case BOOLEAN:
      return row.getBoolean(ord);
    case INTEGER:
      return row.getInt(ord);
    case LONG:
      return row.getLong(ord);
    case FLOAT:
      return row.getFloat(ord);
    case DOUBLE:
      return row.getDouble(ord);
    case STRING:
      return row.getString(ord);
    case BINARY:
    case FIXED:
    case UUID:
      return row.get(ord);
    case DATE:
      return row.getDate(ord);
    case TIMESTAMP:
      return row.getTimestamp(ord);
    case DECIMAL:
      return row.getDecimal(ord);
    default:
      throw new IllegalArgumentException("Unhandled type " + type);
  }
}
 
Example 6
Source File: TestHelpers.java    From iceberg with Apache License 2.0 5 votes vote down vote up
private static Object getPrimitiveValue(Row row, int ord, Type type) {
  if (row.isNullAt(ord)) {
    return null;
  }
  switch (type.typeId()) {
    case BOOLEAN:
      return row.getBoolean(ord);
    case INTEGER:
      return row.getInt(ord);
    case LONG:
      return row.getLong(ord);
    case FLOAT:
      return row.getFloat(ord);
    case DOUBLE:
      return row.getDouble(ord);
    case STRING:
      return row.getString(ord);
    case BINARY:
    case FIXED:
    case UUID:
      return row.get(ord);
    case DATE:
      return row.getDate(ord);
    case TIMESTAMP:
      return row.getTimestamp(ord);
    case DECIMAL:
      return row.getDecimal(ord);
    default:
      throw new IllegalArgumentException("Unhandled type " + type);
  }
}
 
Example 7
Source File: JavaUserDefinedUntypedAggregation.java    From nemo with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the given aggregation buffer `buffer` with new input data from `input`.
 *
 * @param buffer buffer to update.
 * @param input input to update with.
 */
public void update(final MutableAggregationBuffer buffer, final Row input) {
  if (!input.isNullAt(0)) {
    long updatedSum = buffer.getLong(0) + input.getLong(0);
    long updatedCount = buffer.getLong(1) + 1;
    buffer.update(0, updatedSum);
    buffer.update(1, updatedCount);
  }
}
 
Example 8
Source File: JavaUserDefinedUntypedAggregation.java    From nemo with Apache License 2.0 5 votes vote down vote up
/**
 * Merges two aggregation buffers and stores the updated buffer values back to `buffer1`.
 *
 * @param buffer1 first buffer.
 * @param buffer2 second buffer.
 */
public void merge(final MutableAggregationBuffer buffer1, final Row buffer2) {
  long mergedSum = buffer1.getLong(0) + buffer2.getLong(0);
  long mergedCount = buffer1.getLong(1) + buffer2.getLong(1);
  buffer1.update(0, mergedSum);
  buffer1.update(1, mergedCount);
}
 
Example 9
Source File: DependencyLinkSpanIterator.java    From zipkin-dependencies with Apache License 2.0 5 votes vote down vote up
@Override
public Iterator<Span> next() {
  Row peeked = delegate.peek();
  currentTraceIdHi = hasTraceIdHigh ? peeked.getLong(0) : 0L;
  currentTraceIdLo = peeked.getLong(traceIdIndex);
  return new DependencyLinkSpanIterator(
      delegate, traceIdIndex, currentTraceIdHi, currentTraceIdLo);
}
 
Example 10
Source File: SQLLongint.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void read(Row row, int ordinal) throws StandardException {
	if (row.isNullAt(ordinal))
		setToNull();
	else {
		isNull = false;
		value = row.getLong(ordinal);
	}
}
 
Example 11
Source File: JavaUserDefinedUntypedAggregation.java    From incubator-nemo with Apache License 2.0 2 votes vote down vote up
/**
 * Calculates the final result.
 *
 * @param buffer buffer row.
 * @return the result.
 */
public Double evaluate(final Row buffer) {
  return ((double) buffer.getLong(0)) / buffer.getLong(1);
}
 
Example 12
Source File: JavaUserDefinedUntypedAggregation.java    From nemo with Apache License 2.0 2 votes vote down vote up
/**
 * Calculates the final result.
 *
 * @param buffer buffer row.
 * @return the result.
 */
public Double evaluate(final Row buffer) {
  return ((double) buffer.getLong(0)) / buffer.getLong(1);
}