Java Code Examples for org.apache.samza.operators.KV#getKey()

The following examples show how to use org.apache.samza.operators.KV#getKey() . 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: OperatorImplGraph.java    From samza with Apache License 2.0 6 votes vote down vote up
private PartialJoinOperatorImpl getOrCreatePartialJoinOpImpls(JoinOperatorSpec joinOpSpec, boolean isLeft,
    Clock clock) {
  // get the per task pair of PartialJoinOperatorImpl for the corresponding {@code joinOpSpec}
  KV<PartialJoinOperatorImpl, PartialJoinOperatorImpl> partialJoinOpImpls = joinOpImpls.computeIfAbsent(joinOpSpec.getOpId(),
    joinOpId -> {
      PartialJoinFunction leftJoinFn = createLeftJoinFn(joinOpSpec);
      PartialJoinFunction rightJoinFn = createRightJoinFn(joinOpSpec);
      return new KV(new PartialJoinOperatorImpl(joinOpSpec, true, leftJoinFn, rightJoinFn, clock),
          new PartialJoinOperatorImpl(joinOpSpec, false, rightJoinFn, leftJoinFn, clock));
    });

  if (isLeft) { // we got here from the left side of the join
    return partialJoinOpImpls.getKey();
  } else { // we got here from the right side of the join
    return partialJoinOpImpls.getValue();
  }
}
 
Example 2
Source File: AvroRelConverter.java    From samza with Apache License 2.0 6 votes vote down vote up
/**
 * Converts the nested avro object in SamzaMessage to relational message corresponding to
 * the tableName with relational schema.
 */
@Override
public SamzaSqlRelMessage convertToRelMessage(KV<Object, Object> samzaMessage) {
  List<String> payloadFieldNames = new ArrayList<>();
  List<Object> payloadFieldValues = new ArrayList<>();
  Object value = samzaMessage.getValue();
  if (value instanceof IndexedRecord) {
    fetchFieldNamesAndValuesFromIndexedRecord((IndexedRecord) value, payloadFieldNames, payloadFieldValues,
        payloadSchema);
  } else if (value == null) {
    // If the payload is null, set each record value as null
    payloadFieldNames.addAll(payloadSchema.getFields().stream().map(Schema.Field::name).collect(Collectors.toList()));
    IntStream.range(0, payloadFieldNames.size()).forEach(x -> payloadFieldValues.add(null));
  } else {
    String msg = "Avro message converter doesn't support messages of type " + value.getClass();
    LOG.error(msg);
    throw new SamzaException(msg);
  }

  return new SamzaSqlRelMessage(samzaMessage.getKey(), payloadFieldNames, payloadFieldValues,
      new SamzaSqlRelMsgMetadata(0L, 0L));
}
 
Example 3
Source File: JobNodeConfigurationGenerator.java    From samza with Apache License 2.0 5 votes vote down vote up
private void addSerdes(KV<Serde, Serde> serdes, String streamId, Map<String, Serde> keySerdeMap,
    Map<String, Serde> msgSerdeMap) {
  if (serdes != null) {
    if (serdes.getKey() != null && !(serdes.getKey() instanceof NoOpSerde)) {
      keySerdeMap.put(streamId, serdes.getKey());
    }
    if (serdes.getValue() != null && !(serdes.getValue() instanceof NoOpSerde)) {
      msgSerdeMap.put(streamId, serdes.getValue());
    }
  }
}
 
Example 4
Source File: StreamTableJoinExample.java    From samza-hello-samza with Apache License 2.0 4 votes vote down vote up
@Override
public String getRecordKey(KV<String, Profile> record) {
  return record.getKey();
}
 
Example 5
Source File: StreamTableJoinExample.java    From samza-hello-samza with Apache License 2.0 4 votes vote down vote up
@Override
public String getMessageKey(KV<String, PageView> message) {
  return message.getKey();
}
 
Example 6
Source File: StreamTableJoinExample.java    From samza-hello-samza with Apache License 2.0 4 votes vote down vote up
@Override
public EnrichedPageView apply(KV<String, PageView> message, KV<String, Profile> record) {
  return record == null ? null :
      new EnrichedPageView(message.getKey(), record.getValue().company, message.getValue().pageId);
}
 
Example 7
Source File: RemoteTableJoinExample.java    From samza-hello-samza with Apache License 2.0 4 votes vote down vote up
@Override
public String getRecordKey(KV<String, Double> record) {
  return record.getKey();
}
 
Example 8
Source File: RemoteTableJoinExample.java    From samza-hello-samza with Apache License 2.0 4 votes vote down vote up
@Override
public String getMessageKey(KV<String, Void> message) {
  return message.getKey();
}
 
Example 9
Source File: RemoteTableJoinExample.java    From samza-hello-samza with Apache License 2.0 4 votes vote down vote up
@Override
public StockPrice apply(KV<String, Void> message, KV<String, Double> record) {
  return record == null ? null : new StockPrice(message.getKey(), record.getValue());
}
 
Example 10
Source File: PageViewToProfileJoinFunction.java    From samza with Apache License 2.0 4 votes vote down vote up
@Override
public Integer getRecordKey(KV<Integer, TestTableData.Profile> record) {
  return record.getKey();
}
 
Example 11
Source File: PageViewToProfileJoinFunction.java    From samza with Apache License 2.0 4 votes vote down vote up
@Override
public Integer getMessageKey(KV<Integer, TestTableData.PageView> message) {
  return message.getKey();
}
 
Example 12
Source File: PageViewToProfileJoinFunction.java    From samza with Apache License 2.0 4 votes vote down vote up
@Override
public TestTableData.EnrichedPageView apply(KV<Integer, TestTableData.PageView> m, KV<Integer, TestTableData.Profile> r) {
  return r == null ? null : new TestTableData.EnrichedPageView(m.getValue().getPageKey(), m.getKey(), r.getValue().getCompany());
}
 
Example 13
Source File: TestCouchbaseRemoteTableEndToEnd.java    From samza with Apache License 2.0 4 votes vote down vote up
@Override
public String getRecordKey(KV<String, String> record) {
  return record.getKey();
}
 
Example 14
Source File: TestCouchbaseRemoteTableEndToEnd.java    From samza with Apache License 2.0 4 votes vote down vote up
@Override
public String getMessageKey(KV<String, String> message) {
  return message.getKey();
}
 
Example 15
Source File: SamzaSqlLocalTableJoinFunction.java    From samza with Apache License 2.0 4 votes vote down vote up
@Override
public SamzaSqlRelRecord getRecordKey(KV<SamzaSqlRelRecord, SamzaSqlRelMessage> record) {
  return record.getKey();
}
 
Example 16
Source File: SamzaSqlRemoteTableJoinFunction.java    From samza with Apache License 2.0 4 votes vote down vote up
@Override
public Object getRecordKey(KV record) {
  return record.getKey();
}
 
Example 17
Source File: TestWindowOperator.java    From samza with Apache License 2.0 4 votes vote down vote up
@Override
public IntegerEnvelope apply(KV<Integer, Integer> message) {
  return new IntegerEnvelope(message.getKey());
}