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

[CT-2853] dbt show --output json converts integers to scale-1 numerics #8167

Closed
jtcohen6 opened this issue Jul 20, 2023 · 1 comment
Closed
Labels
bug Something isn't working duplicate This issue or pull request already exists
Milestone

Comments

@jtcohen6
Copy link
Contributor

jtcohen6 commented Jul 20, 2023

This is quite the throwback :) #3499

It looks like dbt show --output json is incorrectly serializing integer values to scale-1 numeric (decimal) values. That is, JSON number instead of JSON integer.

-- models/my_model.sql
select '0005' as stringnum, 'false' as stringbool, 10 as intfield, false as boolfield, '01T00000aabbccdd' as dtstring
union all
select '0006' as stringnum, 'true' as stringbool, 20 as intfield, true as boolfield, '01T00000aabbccde' as dtstring
$ dbt show -s my_model
12:51:50  Running with dbt=1.5.2
12:51:50  Registered adapter: postgres=1.5.2
12:51:50  Found 1 model, 0 tests, 0 snapshots, 0 analyses, 308 macros, 0 operations, 1 seed file, 0 sources, 0 exposures, 0 metrics, 0 groups
12:51:50
12:51:50  Concurrency: 5 threads (target='dev')
12:51:50
12:51:50  Previewing node 'my_model':
| stringnum | stringbool | intfield | boolfield | dtstring         |
| --------- | ---------- | -------- | --------- | ---------------- |
| 0005      | false      |       10 |     False | 01T00000aabbccdd |
| 0006      | true       |       20 |      True | 01T00000aabbccde |
$ dbt show -s my_model --output json
12:55:15  Running with dbt=1.5.2
12:55:15  Registered adapter: postgres=1.5.2
12:55:15  Found 1 model, 0 tests, 0 snapshots, 0 analyses, 308 macros, 0 operations, 1 seed file, 0 sources, 0 exposures, 0 metrics, 0 groups
12:55:15
12:55:15  Concurrency: 5 threads (target='dev')
12:55:15
12:55:15  {
  "node": "my_model",
  "show": [
    {
      "stringnum": "0005",
      "stringbool": "false",
      "intfield": 10.0,
      "boolfield": false,
      "dtstring": "01T00000aabbccdd"
    },
    {
      "stringnum": "0006",
      "stringbool": "true",
      "intfield": 20.0,
      "boolfield": true,
      "dtstring": "01T00000aabbccde"
    }
  ]
}

What's going on?

We're just using the agate library's type system and JSON serialization:

table = result.agate_table
# Hack to get Agate table output as string
output = io.StringIO()
if self.args.output == "json":
table.to_json(path=output)

This is being returned and saved as a decimal.Decimal type, rather than a Python int.

ipdb> table
<agate.table.Table object at 0x1078d1360>
ipdb> [list(row) for row in table]
[['0005', 'false', Decimal('10'), False, '01T00000aabbccdd'], ['0006', 'true', Decimal('20'), True, '01T00000aabbccde']]
ipdb> table.print_json()
[{"stringnum": "0005", "stringbool": "false", "intfield": 10.0, "boolfield": false, "dtstring": "01T00000aabbccdd"}, {"stringnum": "0006", "stringbool": "true", "intfield": 20.0, "boolfield": true, "dtstring": "01T00000aabbccde"}]
ipdb> type(table[0][2])
<class 'decimal.Decimal'>

This is not a regression

It's always been a problem for the dbt Cloud IDE. Here's query in dbt-core v1.4 (+ dbt-rpc):

Screenshot 2023-07-20 at 15 03 50

And using dbt-core v1.6.0-rc1:

Screenshot 2023-07-20 at 15 05 30

But it would be nice to finally fix this, especially now that the power to do so is fully within our grasp :)

@jtcohen6 jtcohen6 added the bug Something isn't working label Jul 20, 2023
@jtcohen6 jtcohen6 added this to the v1.5.x milestone Jul 20, 2023
@github-actions github-actions bot changed the title dbt show --output json converts integers to scale-1 numerics [CT-2853] dbt show --output json converts integers to scale-1 numerics Jul 20, 2023
@jtcohen6 jtcohen6 added the duplicate This issue or pull request already exists label Jul 20, 2023
@jtcohen6
Copy link
Contributor Author

@dave-connors-3 beat me to it!! #8153

@jtcohen6 jtcohen6 closed this as not planned Won't fix, can't repro, duplicate, stale Jul 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

1 participant