-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Scott Kuehn
committed
Aug 28, 2021
1 parent
4685db1
commit cae8e7b
Showing
9 changed files
with
237 additions
and
45 deletions.
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.