-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
A new includeAllDimension flag for dimensionsSpec #12276
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,22 +33,20 @@ | |
|
||
import javax.annotation.Nullable; | ||
import java.util.ArrayList; | ||
import java.util.LinkedHashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public class MapInputRowParser implements InputRowParser<Map<String, Object>> | ||
{ | ||
private final ParseSpec parseSpec; | ||
private final List<String> dimensions; | ||
|
||
@JsonCreator | ||
public MapInputRowParser( | ||
@JsonProperty("parseSpec") ParseSpec parseSpec | ||
) | ||
{ | ||
this.parseSpec = parseSpec; | ||
this.dimensions = parseSpec.getDimensionsSpec().getDimensionNames(); | ||
} | ||
|
||
@Override | ||
|
@@ -57,8 +55,7 @@ public List<InputRow> parseBatch(Map<String, Object> theMap) | |
return ImmutableList.of( | ||
parse( | ||
parseSpec.getTimestampSpec(), | ||
dimensions, | ||
parseSpec.getDimensionsSpec().getDimensionExclusions(), | ||
parseSpec.getDimensionsSpec(), | ||
theMap | ||
) | ||
); | ||
|
@@ -69,29 +66,45 @@ public static InputRow parse(InputRowSchema inputRowSchema, Map<String, Object> | |
return parse(inputRowSchema.getTimestampSpec(), inputRowSchema.getDimensionsSpec(), theMap); | ||
} | ||
|
||
private static InputRow parse( | ||
TimestampSpec timestampSpec, | ||
/** | ||
* Finds the final set of dimension names to use for {@link InputRow}. | ||
* There are 3 cases here. | ||
* | ||
* 1) If {@link DimensionsSpec#isIncludeAllDimensions()} is set, the returned list includes _both_ | ||
* {@link DimensionsSpec#getDimensionNames()} and the dimensions in the given map ({@code rawInputRow#keySet()}). | ||
* 2) If isIncludeAllDimensions is not set and {@link DimensionsSpec#getDimensionNames()} is not empty, | ||
* the dimensions in dimensionsSpec is returned. | ||
* 3) If isIncludeAllDimensions is not set and {@link DimensionsSpec#getDimensionNames()} is empty, | ||
* the dimensions in the given map is returned. | ||
* | ||
* In any case, the returned list does not include any dimensions in {@link DimensionsSpec#getDimensionExclusions()}. | ||
*/ | ||
private static List<String> findDimensions( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add some comment here on
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added javadoc and renamed |
||
DimensionsSpec dimensionsSpec, | ||
Map<String, Object> theMap | ||
) throws ParseException | ||
Map<String, Object> rawInputRow | ||
) | ||
{ | ||
return parse(timestampSpec, dimensionsSpec.getDimensionNames(), dimensionsSpec.getDimensionExclusions(), theMap); | ||
if (dimensionsSpec.isIncludeAllDimensions()) { | ||
LinkedHashSet<String> dimensions = new LinkedHashSet<>(dimensionsSpec.getDimensionNames()); | ||
dimensions.addAll(Sets.difference(rawInputRow.keySet(), dimensionsSpec.getDimensionExclusions())); | ||
return new ArrayList<>(dimensions); | ||
} else { | ||
if (!dimensionsSpec.getDimensionNames().isEmpty()) { | ||
return dimensionsSpec.getDimensionNames(); | ||
} else { | ||
return new ArrayList<>(Sets.difference(rawInputRow.keySet(), dimensionsSpec.getDimensionExclusions())); | ||
} | ||
} | ||
} | ||
|
||
@VisibleForTesting | ||
static InputRow parse( | ||
TimestampSpec timestampSpec, | ||
List<String> dimensions, | ||
Set<String> dimensionExclusions, | ||
DimensionsSpec dimensionsSpec, | ||
Map<String, Object> theMap | ||
) throws ParseException | ||
{ | ||
final List<String> dimensionsToUse; | ||
if (!dimensions.isEmpty()) { | ||
dimensionsToUse = dimensions; | ||
} else { | ||
dimensionsToUse = new ArrayList<>(Sets.difference(theMap.keySet(), dimensionExclusions)); | ||
} | ||
final List<String> dimensionsToUse = findDimensions(dimensionsSpec, theMap); | ||
|
||
final DateTime timestamp; | ||
try { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I forget the jackson behaviour, but does having a primitive
boolean
here break the deserialization if the flagincludeAllDimensions
is absent?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
boolean
variables are initialized to false when they are missing.