This repository has been archived by the owner on Jan 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
feat: add read task in bigquery component #156
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
65d3d8c
feat: add read task in bigquery component
chuang8511 edf3751
feat: add functions to init dynamic schema
chuang8511 497abd2
feat: finish read task implementation in bigquery component
chuang8511 9bd550c
chore: add todo for future development
chuang8511 a89daf6
chore: add description in document
chuang8511 6ec3ef9
feat: dynamically make kebab-case
chuang8511 9592d81
feat: handle no table found case
chuang8511 cb2743b
fix: fix lint error
chuang8511 9783aa1
fix: convert snake to kebab when searching input
chuang8511 91cf866
chore: add comment
chuang8511 acf8541
fix: revert bigquery schema customization
chuang8511 db4a90b
fix: fix conflict error
chuang8511 7f1503a
chore: take out the unnecessary parts
chuang8511 71fa8fe
chore: update document
chuang8511 3f82148
fix: fix bug after recipe revamp
chuang8511 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
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,3 @@ | ||
// TODO: chuang8511, add test code | ||
// It will be done before 2024-06-26. | ||
package bigquery |
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,59 @@ | ||
package bigquery | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"cloud.google.com/go/bigquery" | ||
"google.golang.org/api/iterator" | ||
) | ||
|
||
type ReadInput struct { | ||
ProjectID string | ||
DatasetID string | ||
TableName string | ||
Client *bigquery.Client | ||
Filtering string | ||
} | ||
|
||
type ReadOutput struct { | ||
Data []map[string]any `json:"data"` | ||
} | ||
|
||
func queryBuilder(input ReadInput) string { | ||
if input.Filtering == "" { | ||
return fmt.Sprintf("SELECT * FROM `%s.%s.%s`", input.ProjectID, input.DatasetID, input.TableName) | ||
} | ||
return fmt.Sprintf("SELECT * FROM `%s.%s.%s` %s", input.ProjectID, input.DatasetID, input.TableName, input.Filtering) | ||
} | ||
|
||
func readDataFromBigQuery(input ReadInput) (ReadOutput, error) { | ||
|
||
ctx := context.Background() | ||
client := input.Client | ||
|
||
sql := queryBuilder(input) | ||
q := client.Query(sql) | ||
it, err := q.Read(ctx) | ||
if err != nil { | ||
return ReadOutput{}, err | ||
} | ||
result := []map[string]any{} | ||
for { | ||
var values []bigquery.Value | ||
err := it.Next(&values) | ||
|
||
if err == iterator.Done { | ||
break | ||
} | ||
data := map[string]any{} | ||
|
||
for i, schema := range it.Schema { | ||
data[schema.Name] = values[i] | ||
} | ||
|
||
result = append(result, data) | ||
} | ||
|
||
return ReadOutput{Data: result}, nil | ||
} |
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.
How about we only fetch the table we want to use?
If we still want to fetch multiple tables, we can use a map with table_name as the key.
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.
@donch1989
I was thinking to take the table name from setting parts to input.
Then, the users can choose the table / tables they want to extract with smart hint or drag-and-drop menu.
And, we also can adjust the columns without saving pipeline again if users want to change table.
What do you think about that?
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.
Yeah, sounds good
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.
I have created another ticket and leave TODO memo here.
I will deal with it in the near future.