This repository has been archived by the owner on Oct 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
add insert support #32
Draft
skuehn
wants to merge
1
commit into
GoogleCloudPlatform:master
Choose a base branch
from
skuehn:skuehn/add-insert-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
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
58 changes: 58 additions & 0 deletions
58
src/main/java/com/google/cloud/solutions/datalineage/extractor/InsertStatementExtractor.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,58 @@ | ||
package com.google.cloud.solutions.datalineage.extractor; | ||
|
||
import static com.google.cloud.solutions.datalineage.converter.ResolvedColumnToColumnEntityConverter.convertToColumnEntity; | ||
|
||
import com.google.cloud.solutions.datalineage.model.LineageMessages.ColumnEntity; | ||
import com.google.cloud.solutions.datalineage.model.LineageMessages.ColumnLineage; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableMap; | ||
import com.google.zetasql.resolvedast.ResolvedColumn; | ||
import com.google.zetasql.resolvedast.ResolvedNodes; | ||
import java.util.HashMap; | ||
import java.util.stream.IntStream; | ||
|
||
public class InsertStatementExtractor extends ColumnLineageExtractor { | ||
|
||
public InsertStatementExtractor(ResolvedNodes.ResolvedStatement resolvedStatement) { | ||
super(resolvedStatement); | ||
} | ||
|
||
@Override | ||
public String getSupportedColumnType() { | ||
// TODO skuehn this PR determine how to support column types and the extractor instantiation | ||
// optimizations | ||
return null; | ||
} | ||
|
||
@Override | ||
public ImmutableMap<ColumnEntity, ColumnLineage> extract() { | ||
HashMap<ColumnEntity, ColumnLineage> exprLineageMapBuilder = new HashMap<>(); | ||
|
||
resolvedStatement.accept( | ||
new ResolvedNodes.Visitor() { | ||
@Override | ||
public void visit(ResolvedNodes.ResolvedInsertStmt insertStmt) { | ||
if (!insertStmt.getQueryOutputColumnList().isEmpty()) { | ||
// For inserts, BQ requires values to be added in the same order as the specified | ||
// columns, and the number of values added must match the number of specified columns. | ||
IntStream.range(0, insertStmt.getInsertColumnList().size()).forEach(columnIndex -> { | ||
ColumnEntity outputColumn = | ||
convertToColumnEntity(insertStmt.getInsertColumnList().get(columnIndex)); | ||
ResolvedColumn sourceColumn = insertStmt.getQueryOutputColumnList() | ||
.get(columnIndex); | ||
|
||
exprLineageMapBuilder.put( | ||
outputColumn, | ||
ColumnLineage.newBuilder() | ||
.setTarget(outputColumn) | ||
.addAllParents(ImmutableList.of(convertToColumnEntity(sourceColumn))) | ||
.build()); | ||
}); | ||
} | ||
super.visit(insertStmt); | ||
} | ||
}); | ||
|
||
return ImmutableMap.copyOf(exprLineageMapBuilder); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2020 Google LLC | ||
* | ||
* 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. | ||
*/ | ||
-- | ||
-- 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. | ||
|
||
#standardSQL | ||
INSERT | ||
`project1.datasetA.TableA` | ||
SELECT | ||
colB, | ||
colC | ||
FROM | ||
`project2.datasetB.TableB` |
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.
The extractor types and ordering is still necessary - this has just been temporarily disabled. One question is how extractors work in order (or nested?). An insert with
SET col = CONCAT(colA, colB)
will be parsed correctly with colA and colB properly set as parents of col, but the evaluation occurs after the DML statement evaluation and the type is a '$insert'. I think this just needs some extension to allow the ordering of extractors to change, as well as allowing an extractor registered on the table itself instead of columnType (I think this is necessary for DML, but still wrapping my head around it). Any advice appreciated.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.
They work in order