-
-
Notifications
You must be signed in to change notification settings - Fork 338
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
Add target_table_info in tables.list_joinable's
response
#3718
Conversation
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.
Ahh — I see why you requested a different structure. Previously we were returning a JSON object with stringified Django column ids as keys. Now columns require two id values to be uniquely identified, so the old structure is problematic. Interesting!
I'm okay with nesting them.
But in running the code in this PR, I'm seeing some problems.
I'm running this request where 698589 is the oid of the "Books" table in our library management sample data.
{
"jsonrpc": "2.0",
"method": "tables.list_joinable",
"id": 0,
"params": {
"database_id": 1,
"table_oid": 698589,
"max_depth": 1
}
}
Here are some changes I'd like to see:
-
Ensure that the
joinable_tables
andtarget_table_info
arrays don't contain duplicates. There's something fishy going on somewhere. I have a hunch it's some kind of SQL join or aggregation problem. I'm expecting to see three results in each of these arrays. But instead I see 9. -
Restructure the
target_table_info
value. Currently it's an array of objects. An each object contains an entry which has a key of the table OID and a value of the table name. This would be very bad JSON schema design, so I don't imagine you did this intentionally. It looks like a bug. Instead of an array of objects, I'd like to see a single object where each entry has the table OID as the key and then an object as the value.You have:
{ "target_table_info": [ { "698581": "Authors", "columns": [] } ] }
I want:
{ "target_table_info": { "698581": { "name": "Authors", "columns": [] } } }
I think I've addressed your feedback @seancolsen, Here is the response for the "Books" table with depth=1. Response{
"joinable_tables": [
{
"base": 2254321,
"depth": 1,
"target": 2254313,
"fkey_path": [
[2254389, false]
],
"join_path": [
[
[2254321, 10],
[2254313, 1]
]
],
"multiple_results": false
},
{
"base": 2254321,
"depth": 1,
"target": 2254358,
"fkey_path": [
[2254394, false]
],
"join_path": [
[
[2254321, 11],
[2254358, 1]
]
],
"multiple_results": false
},
{
"base": 2254321,
"depth": 1,
"target": 2254334,
"fkey_path": [
[2254399, true]
],
"join_path": [
[
[2254321, 1],
[2254334, 5]
]
],
"multiple_results": true
}
],
"target_table_info": {
"2254313": {
"name": "Authors",
"columns": [
{"name": "id" , "type": "integer", "attnum": 1},
{"name": "Last Name" , "type": "text" , "attnum": 3},
{"name": "First Name", "type": "text" , "attnum": 2}
]
},
"2254334": {
"name": "Items",
"columns": [
{"name": "id" , "type": "integer", "attnum": 1},
{"name": "Book" , "type": "integer", "attnum": 5},
{"name": "Acquisition Date", "type": "date" , "attnum": 3},
{"name": "Barcode" , "type": "text" , "attnum": 2}
]
},
"2254358": {
"name": "Publishers",
"columns": [
{"name": "id" , "type": "integer", "attnum": 1},
{"name": "Name", "type": "text" , "attnum": 2}
]
}
}
}
Do you have an opinion on whether the |
Good question, @Anish9901. Can you please put the columns data in an object too? Stringified attnums as keys. |
Done @seancolsen. Here is the updated response: {
"joinable_tables": [
{
"base": 2254321,
"depth": 1,
"target": 2254313,
"fkey_path": [
[2254389, false]
],
"join_path": [
[
[2254321, 10],
[2254313, 1]
]
],
"multiple_results": false
},
{
"base": 2254321,
"depth": 1,
"target": 2254358,
"fkey_path": [
[2254394, false]
],
"join_path": [
[
[2254321, 11],
[2254358, 1]
]
],
"multiple_results": false
},
{
"base": 2254321,
"depth": 1,
"target": 2254334,
"fkey_path": [
[2254399, true]
],
"join_path": [
[
[2254321, 1],
[2254334, 5]
]
],
"multiple_results": true
}
],
"target_table_info": {
"2254313": {
"name": "Authors",
"columns": {
"1": {"name": "id" , "type": "integer"},
"2": {"name": "First Name", "type": "text" },
"3": {"name": "Last Name" , "type": "text" }
}
},
"2254334": {
"name": "Items",
"columns": {
"1": {"name": "id" , "type": "integer"},
"2": {"name": "Barcode" , "type": "text" },
"3": {"name": "Acquisition Date", "type": "date" },
"5": {"name": "Book" , "type": "integer"}
}
},
"2254358": {
"name": "Publishers",
"columns": {
"1": {"name": "id" , "type": "integer"},
"2": {"name": "Name", "type": "text" }
}
}
}
} |
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.
Overall, not bad. Given that we're waiting for feedback from Sean, I think it's a good idea to take another pass through the SQL function and tighten a couple of screws. See my specific comments.
db/sql/10_msar_joinable_tables.sql
Outdated
joinable_tables jsonb; | ||
target_table_info jsonb; | ||
BEGIN | ||
CREATE TEMP TABLE jt_cte AS |
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.
Why make this a temp table rather than a proper CTE here? It's
- slightly less performant under some conditions (i.e., when it's small, and
- affects the volatility setting, meaning it's slower for callers
db/sql/10_msar_joinable_tables.sql
Outdated
'target_table_info', target_table_info | ||
); | ||
END; | ||
$$ LANGUAGE plpgsql RETURNS NULL ON NULL INPUT; |
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.
If you change the temp table to a CTE, you should mark this as STABLE
.
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.
LGTM. Nice!
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.
This is great. Thanks!
Fixes #3713
Checklist
Update index.md
).develop
branch of the repositoryvisible errors.
Developer Certificate of Origin
Developer Certificate of Origin