Skip to content

Update import timestamp after spanner ignestion#586

Open
vish-cs wants to merge 1 commit into
datacommonsorg:masterfrom
vish-cs:dashboard
Open

Update import timestamp after spanner ignestion#586
vish-cs wants to merge 1 commit into
datacommonsorg:masterfrom
vish-cs:dashboard

Conversation

@vish-cs

@vish-cs vish-cs commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

DataImportTimestamp currently tracks the time when the data is available in STAGING state (after batch job). It may be more meaningful to use this column to reflect the time for spanner ingestion.

@vish-cs vish-cs requested a review from n-h-diaz June 24, 2026 16:46

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request shifts the setting of DataImportTimestamp in Spanner from the staging phase to when the ingestion status is successfully updated, and adds corresponding unit tests. The feedback suggests refactoring the SQL update query to construct it dynamically, which reduces code duplication and improves maintainability.

Comment on lines +265 to +277
if status == 'SUCCESS':
update_sql = (
"UPDATE ImportStatus SET State = @importStatus, WorkflowId = @workflowId, "
"StatusUpdateTimestamp = PENDING_COMMIT_TIMESTAMP(), "
"DataImportTimestamp = PENDING_COMMIT_TIMESTAMP() "
"WHERE ImportName IN UNNEST(@importNames)"
)
else:
update_sql = (
"UPDATE ImportStatus SET State = @importStatus, WorkflowId = @workflowId, "
"StatusUpdateTimestamp = PENDING_COMMIT_TIMESTAMP() "
"WHERE ImportName IN UNNEST(@importNames)"
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The SQL update query is duplicated with only a minor difference (the addition of DataImportTimestamp when status == 'SUCCESS'). We can construct the query dynamically to avoid duplication and improve maintainability.

            set_clauses = [
                "State = @importStatus",
                "WorkflowId = @workflowId",
                "StatusUpdateTimestamp = PENDING_COMMIT_TIMESTAMP()"
            ]
            if status == 'SUCCESS':
                set_clauses.append("DataImportTimestamp = PENDING_COMMIT_TIMESTAMP()")
            update_sql = f"UPDATE ImportStatus SET {', '.join(set_clauses)} WHERE ImportName IN UNNEST(@importNames)"

@codacy-production

codacy-production Bot commented Jun 24, 2026

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 1 high · 2 medium

Alerts:
⚠ 3 issues (≤ 0 issues of at least minor severity)

Results:
3 new issues

Category Results
UnusedCode 1 medium
ErrorProne 1 high
Security 1 medium

View in Codacy

🟢 Metrics 7 complexity

Metric Results
Complexity 7

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants