-
Notifications
You must be signed in to change notification settings - Fork 341
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
CDAP-16708 add API for autojoiner #12185
Merged
albertshau
merged 1 commit into
release/6.1
from
feature_release/CDAP-16708-new-joiner-api
May 19, 2020
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
56 changes: 56 additions & 0 deletions
56
...lates/cdap-etl/cdap-etl-api/src/main/java/io/cdap/cdap/etl/api/batch/BatchAutoJoiner.java
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright © 2020 Cask Data, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package io.cdap.cdap.etl.api.batch; | ||
|
||
import io.cdap.cdap.api.annotation.Beta; | ||
import io.cdap.cdap.etl.api.MultiInputPipelineConfigurable; | ||
import io.cdap.cdap.etl.api.MultiInputPipelineConfigurer; | ||
import io.cdap.cdap.etl.api.join.AutoJoiner; | ||
|
||
/** | ||
* Joins input data, leaving implementation details up to the application. | ||
*/ | ||
@Beta | ||
public abstract class BatchAutoJoiner extends MultiInputBatchConfigurable<BatchJoinerContext> | ||
implements AutoJoiner, MultiInputPipelineConfigurable { | ||
public static final String PLUGIN_TYPE = BatchJoiner.PLUGIN_TYPE; | ||
|
||
/** | ||
* Configure the pipeline. This is run once when the pipeline is being published. | ||
* This is where you perform any static logic, like creating required datasets, performing schema validation, | ||
* setting output schema, and things of that nature. | ||
* | ||
* @param multiInputPipelineConfigurer the configurer used to add required datasets and streams | ||
*/ | ||
@Override | ||
public void configurePipeline(MultiInputPipelineConfigurer multiInputPipelineConfigurer) { | ||
// no-op | ||
} | ||
|
||
/** | ||
* Prepare a pipeline run. This is run every time before a pipeline runs in order to help set up the run. | ||
* This is where you would set things like the number of partitions to use when joining, and setting the | ||
* join key class if they are not known at compile time. | ||
* | ||
* @param context batch execution context | ||
* @throws Exception | ||
*/ | ||
@Override | ||
public void prepareRun(BatchJoinerContext context) throws Exception { | ||
//no-op | ||
} | ||
} |
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
65 changes: 65 additions & 0 deletions
65
...p-templates/cdap-etl/cdap-etl-api/src/main/java/io/cdap/cdap/etl/api/join/AutoJoiner.java
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright © 2020 Cask Data, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package io.cdap.cdap.etl.api.join; | ||
|
||
import io.cdap.cdap.api.annotation.Beta; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Joins data from two or more input stages together. | ||
* | ||
* For example, the following represents a left outer join on 'purchases'.'user_id' = 'users'.'id': | ||
* | ||
* <pre> | ||
* {@code | ||
* JoinDefinition define(AutoJoinerContext context) { | ||
* JoinStage purchases = JoinStage.builder(context.getInputStages().get("purchases")) | ||
* .isRequired() | ||
* .build(); | ||
* JoinStage users = JoinStage.builder(context.getInputStages().get("users")) | ||
* .isOptional() | ||
* .build(); | ||
* | ||
* JoinCondition condition = JoinCondition.onKeys() | ||
* .addKey(new JoinKey("users", Arrays.asList("id"))) | ||
* .addKey(new JoinKey("purchases", Arrays.asList("user_id"))) | ||
* .build(); | ||
* | ||
* return JoinDefinition.builder() | ||
* // stage name, field name, optional alias | ||
* .select(new Field("purchases", "id", "purchase_id"), | ||
* new Field("purchases", "user_id"), | ||
* new Field("users", "email")) | ||
* .from(purchases, users) | ||
* .on(condition) | ||
* .build() | ||
* } | ||
* } | ||
* </pre> | ||
*/ | ||
@Beta | ||
public interface AutoJoiner { | ||
|
||
/** | ||
* @return definition about what type of join to execute, or null if the definition cannot be created due to | ||
* macro values not being evaluated yet. | ||
*/ | ||
@Nullable | ||
JoinDefinition define(AutoJoinerContext context); | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
...ates/cdap-etl/cdap-etl-api/src/main/java/io/cdap/cdap/etl/api/join/AutoJoinerContext.java
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright © 2020 Cask Data, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package io.cdap.cdap.etl.api.join; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Context for an AutoJoin. | ||
*/ | ||
public interface AutoJoinerContext { | ||
|
||
/** | ||
* @return all input stages | ||
*/ | ||
Map<String, JoinStage> getInputStages(); | ||
} |
83 changes: 83 additions & 0 deletions
83
cdap-app-templates/cdap-etl/cdap-etl-api/src/main/java/io/cdap/cdap/etl/api/join/Field.java
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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright © 2020 Cask Data, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package io.cdap.cdap.etl.api.join; | ||
|
||
import io.cdap.cdap.api.annotation.Beta; | ||
|
||
import java.util.Objects; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* The name of a field and an optional alias to rename it to. | ||
*/ | ||
@Beta | ||
public class Field { | ||
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. Prefer to call this |
||
private final String stageName; | ||
private final String fieldName; | ||
private final String alias; | ||
|
||
public Field(String stageName, String fieldName) { | ||
this(stageName, fieldName, null); | ||
} | ||
|
||
public Field(String stageName, String fieldName, @Nullable String alias) { | ||
this.stageName = stageName; | ||
this.fieldName = fieldName; | ||
this.alias = alias; | ||
} | ||
|
||
public String getStageName() { | ||
return stageName; | ||
} | ||
|
||
public String getFieldName() { | ||
return fieldName; | ||
} | ||
|
||
@Nullable | ||
public String getAlias() { | ||
return alias; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
Field field1 = (Field) o; | ||
return Objects.equals(stageName, field1.stageName) && | ||
Objects.equals(fieldName, field1.fieldName) && | ||
Objects.equals(alias, field1.alias); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(stageName, fieldName, alias); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Field{" + | ||
"stage='" + stageName + '\'' + | ||
", field='" + fieldName + '\'' + | ||
", alias='" + alias + '\'' + | ||
'}'; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...l/cdap-etl-api/src/main/java/io/cdap/cdap/etl/api/join/InvalidJoinConditionException.java
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright © 2020 Cask Data, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package io.cdap.cdap.etl.api.join; | ||
|
||
/** | ||
* Thrown when the join condition is invalid. | ||
*/ | ||
public class InvalidJoinConditionException extends InvalidJoinException { | ||
|
||
public InvalidJoinConditionException(String message) { | ||
super(message); | ||
} | ||
|
||
public InvalidJoinConditionException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...s/cdap-etl/cdap-etl-api/src/main/java/io/cdap/cdap/etl/api/join/InvalidJoinException.java
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright © 2020 Cask Data, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package io.cdap.cdap.etl.api.join; | ||
|
||
/** | ||
* Thrown when a join definition is invalid. | ||
*/ | ||
public class InvalidJoinException extends RuntimeException { | ||
|
||
public InvalidJoinException(String message) { | ||
super(message); | ||
} | ||
|
||
public InvalidJoinException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
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.
nice!