Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: move selectKey impl to plan builder #3362

Merged

Conversation

rodesai
Copy link
Contributor

@rodesai rodesai commented Sep 16, 2019

Description

Moves rekeying from SchemaKStream and into an execution plan builder.

Testing done

Added tests for step builder

Reviewer checklist

  • Ensure docs are updated if necessary. (eg. if a user visible feature is being added or changed).
  • Ensure relevant issues are linked (description should include text like "Fixes #")

@rodesai rodesai requested a review from a team as a code owner September 16, 2019 18:33
Copy link
Contributor

@big-andy-coates big-andy-coates left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @rodesai LGTM

StreamSelectKeyBuilder.build(kstream, selectKey);

// Then:
verify(rekeyedKstream).mapValues(mapperCaptor.capture());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider moving into method to make tests more readable:

    private ValueMapperWithKey<Object, GenericRow, GenericRow> getMapper() { 
       verify(rekeyedKstream).mapValues(mapperCaptor.capture());
       final ValueMapperWithKey<Object, GenericRow, GenericRow> mapper = mapperCaptor.getValue();
    }

Same for others.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider moving into method to make tests more readable:

    private ValueMapperWithKey<Object, GenericRow, GenericRow> getMapper() { 
       verify(rekeyedKstream).mapValues(mapperCaptor.capture());
       final ValueMapperWithKey<Object, GenericRow, GenericRow> mapper = mapperCaptor.getValue();
    }

Same for others.

Copy link
Contributor

@big-andy-coates big-andy-coates left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double checked this PR after seeing issues with raw types and generics in the other related PRs... looks like this one has some minor generic issues to clean up too.

final QueryContext.Stacker stacker,
final ExecutionStep<KStream<K, GenericRow>> source,
final String fieldName,
final boolean updateRowKey
) {
final QueryContext queryContext = stacker.getQueryContext();
return new StreamSelectKey<>(
return (StreamSelectKey<KStream<Struct, GenericRow>>) new StreamSelectKey(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use of raw type.

We need to get the generics right here.

Will StreamSelectKey always build a KStream<Struct, GenericRow> regardless of whether it's source is KStream<Windowed<Struct>, GenericRow> or KStream<Struct, GenericRow>??? I think it does, right?

That being the case, StreamSelectKey should be defined as:

public class StreamSelectKey implements ExecutionStep<KStream<Struct, GenericRow>> {

  private final ExecutionStep<KStream<?, GenericRow>> source;
  ...

  public StreamSelectKey(
      ...
      final ExecutionStep<KStream<?, GenericRow>> source,
     ...
  )

  ...
}

And this method should be:

public static StreamSelectKey streamSelectKey(
      final QueryContext.Stacker stacker,
      final ExecutionStep<KStream<?, GenericRow>> source,
      final String fieldName,
      final boolean updateRowKey
  ) {
    final QueryContext queryContext = stacker.getQueryContext();
    return new StreamSelectKey(
        new DefaultExecutionStepProperties(
            source.getProperties().getSchema(),
            queryContext
        ),
        source,
        fieldName,
        updateRowKey
    );
  }

private static final String KEY = "ATL.BOI";

@Mock
private KStream kstream;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use of raw types - can we please use generic types in tests.

Copy link
Contributor

@big-andy-coates big-andy-coates left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @rodesai, this looks much better!


@Immutable
public class StreamSelectKey<S> implements ExecutionStep<S> {
public class StreamSelectKey<K> implements ExecutionStep<KStream<Struct, GenericRow>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need K here? Can we not just use ExecutionStep<KStream<?, GenericRow>> for the source param / field

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't pass an ExecutionStep<KStream<K, GenericRow>>, which is what SchemaKStream has, to ExecutionStep<KStream<?, GenericRow>>. We could make the type ExecutionStep<? extends KStream<?, GenericRow>>, but this felt easier to read.

StreamSelectKeyBuilder.build(kstream, selectKey);

// Then:
verify(rekeyedKstream).mapValues(mapperCaptor.capture());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider moving into method to make tests more readable:

    private ValueMapperWithKey<Object, GenericRow, GenericRow> getMapper() { 
       verify(rekeyedKstream).mapValues(mapperCaptor.capture());
       final ValueMapperWithKey<Object, GenericRow, GenericRow> mapper = mapperCaptor.getValue();
    }

Same for others.

Moves rekeying from SchemaKStream and into an execution plan builder.
@rodesai rodesai force-pushed the move-select-key-to-plan-builder branch from 79b47d9 to 1f37cdb Compare September 18, 2019 17:57
@rodesai rodesai merged commit f312fcc into confluentinc:master Sep 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants