Skip to content
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

#180 fix for destinationTable not returned #187

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

prabhav007
Copy link

@prabhav007 prabhav007 commented May 11, 2023

closes #180

@@ -1485,7 +1485,7 @@ func (h *jobsInsertHandler) Handle(ctx context.Context, r *jobsInsertRequest) (*
func (h *jobsInsertHandler) addQueryResultToDynamicDestinationTable(ctx context.Context, tx *connection.Tx, r *jobsInsertRequest, response *internaltypes.QueryResponse) error {
projectID := r.project.ID
jobID := r.job.JobReference.JobId
datasetID := jobID
datasetID := "ds_" + jobID

Choose a reason for hiding this comment

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

why this is needed?

Copy link

Choose a reason for hiding this comment

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

Copy link
Owner

Choose a reason for hiding this comment

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

I think the jobID is already unique for each request. So if you just want to make datasetID unique, jobID seems fine.

Copy link

@kromiii kromiii Sep 21, 2023

Choose a reason for hiding this comment

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

It seems fine, but actually, after deleting this ds_ I got an error below when using bigquery ruby client.
Do you know what causes this erorr? @goccy

2023-09-21 21:49:45 bq-emulator-test-bq-1  | 2023-09-21T12:49:45.555Z   ERROR   server/handler.go:2355   internalError   {"error": "internalError: failed to query SELECT * FROM `job_JSsjGMduSIBf5L_poPWkkL2vZdkd`: no such table: test_job_JSsjGMduSIBf5L_poPWkkL2vZdkd"}

Copy link
Owner

Choose a reason for hiding this comment

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

@kromiii Sorry, I don't known by this information. I'd like to have reproducible test code. Go is preferred, but other languages are also acceptable. Also, please attach the logs obtained at that time.

Copy link

@kromiii kromiii Sep 21, 2023

Choose a reason for hiding this comment

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

I created a repo to test this. https://github.com/kromiii/bq-emulator-test
This issue depends on the ruby client, so I attached a simple ruby script for testing bigquery-emulator.

Copy link

Choose a reason for hiding this comment

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

@prabhav007 Let us know the reason of ds_ if you are available.

Copy link
Author

@prabhav007 prabhav007 Oct 2, 2023

Choose a reason for hiding this comment

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

In case of jobs with anonymous tables, when the dataset name and the table name are the same, an error response is received. When they are different, it works fine. PFB the error response I got locally.

http://localhost:9050/bigquery/v2/projects/demo-0d168064/datasets/0ffd9b42-7541-4317-ad16-fad5ec3beb55/tables/0ffd9b42-7541-4317-ad16-fad5ec3beb55/data?maxResults=10&prettyPrint=false

{"error":{"errors":[{"reason":"internalError","location":"","debugInfo":"","message":"failed to query SELECT * FROM 0ffd9b42-7541-4317-ad16-fad5ec3beb55: no such table: demo-0d168064_0ffd9b42-7541-4317-ad16-fad5ec3beb55"}],"code":500,"message":"failed to query SELECT * FROM 0ffd9b42-7541-4317-ad16-fad5ec3beb55: no such table: demo-0d168064_0ffd9b42-7541-4317-ad16-fad5ec3beb55"}}

Copy link

Choose a reason for hiding this comment

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

@prabhav007 Thank you. I could reproduce the error. However, the quetion is that it works well in the python clinent even if the dataset name and the table name is the same. What makes this difference?

Copy link
Author

Choose a reason for hiding this comment

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

I am not sure, I was using the java client for spring.

@pyama86
Copy link

pyama86 commented Aug 25, 2023

I have the same problem. How about I take over if there is no progress?

@kromiii
Copy link

kromiii commented Aug 25, 2023

I applied these changes to my branch, and it resolved the error.
These changes would be necessary for using ruby-client for the bigquery-emulator.

@anderseriksson
Copy link

I applied these changes to my branch, and it resolved the error. These changes would be necessary for using ruby-client for the bigquery-emulator.

Yes your changes and your image solved a similar problem when I issue a query with a specific JobId. I hope we can have this fix merged in to goccy project and image.

@benvdh-incentro
Copy link

benvdh-incentro commented Sep 21, 2023

@yaronneuman it seems your question has been answered 3 weeks ago by someone else. Also others mention the code works well... is there anything that's still keeping you from getting this merged? Getting this fixed can also help to resolve an issue being the discussed in the DBT community:

dbt-labs/dbt-bigquery#358

@goccy can you help perhaps?

@goccy
Copy link
Owner

goccy commented Sep 21, 2023

@benvdh-incentro
Thank you, I've commented https://github.com/goccy/bigquery-emulator/pull/187/files#r1332797665

@benvdh-incentro
Copy link

@goccy I see @prabhav007 and @kromiii have delivered some test code and further rationale behind the current PR, anything else that is still needed to get this merged?

@goccy
Copy link
Owner

goccy commented Oct 24, 2023

The reason I cannot merge this PR is that there is no test code in this repository that corresponds to the modification. If there is no test code, I need to determine the validity of the modification from the diffs, which is currently difficult.

@simi
Copy link

simi commented May 16, 2024

I can confirm this breaks Ruby client. 🤔 Any idea how to move this forward? Even with this patch only query like SELECT * FROM finance_v2_local.statements_2 works, but query like SELECT * FROM finance_v2_local.statements_2 WHERE Artist = 'ABC' fails since missing destination dataset table. It seems to be related to fact if query returns any value. For queries with 0 returned rows it fails per

} else if response.TotalRows > 0 {
.

I have checked BQ response and it returns destination table even for empty result.

@simi
Copy link

simi commented May 18, 2024

@kromiii I can try to help with writing test, but seems destination table is not tested currently at all.

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.

DestinationTable is not being returned when creating a query job without tableDestination
8 participants