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

composite UK is failing #252

Closed
jthandy opened this issue Dec 13, 2016 · 3 comments
Closed

composite UK is failing #252

jthandy opened this issue Dec 13, 2016 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@jthandy
Copy link
Member

jthandy commented Dec 13, 2016

When defining a composite unique key, my archive is failing. It seems like this should work, and the expression is valid (verified in a separate SELECT).

I've defined the following unique key in one of my archives:

unique_key: _sdc_source_key__id || '|' || _sdc_level_0_id

I'm getting this error:

(venv)Tristans-MacBook-Pro:analytics tristan$ dbt archive
Traceback (most recent call last):
  File "/Users/tristan/dev/venv/bin/dbt", line 6, in <module>
    exec(compile(open(__file__).read(), __file__, 'exec'))
  File "/Users/tristan/dev/dbt/scripts/dbt", line 8, in <module>
    dbt.main.main(sys.argv[1:])
  File "/Users/tristan/dev/dbt/dbt/main.py", line 38, in main
    return handle(args)
  File "/Users/tristan/dev/dbt/dbt/main.py", line 52, in handle
    res = run_from_args(parsed)
  File "/Users/tristan/dev/dbt/dbt/main.py", line 85, in run_from_args
    return task.run()
  File "/Users/tristan/dev/dbt/dbt/task/archive.py", line 19, in run
    self.compile()
  File "/Users/tristan/dev/dbt/dbt/task/archive.py", line 15, in compile
    compiled = compiler.compile_archives()
  File "/Users/tristan/dev/dbt/dbt/compilation.py", line 412, in compile_archives
    sql = archive.compile()
  File "/Users/tristan/dev/dbt/dbt/model.py", line 705, in compile
    query = archival.compile()
  File "/Users/tristan/dev/dbt/dbt/archival.py", line 41, in compile
    self.schema.create_table(target_schema, target_table, dest_columns, sort=updated_at, dist=unique_key)
  File "/Users/tristan/dev/dbt/dbt/schema.py", line 257, in create_table
    self.execute_and_handle_permissions(sql, table)
  File "/Users/tristan/dev/dbt/dbt/schema.py", line 159, in execute_and_handle_permissions
    return self.execute(query)
  File "/Users/tristan/dev/dbt/dbt/schema.py", line 137, in execute
    raise e
  File "/Users/tristan/dev/dbt/dbt/schema.py", line 129, in execute
    cursor.execute(sql)
psycopg2.NotSupportedError: column "_sdc_source_key__id || '|' || _sdc_level_0_id" specified as distkey/sortkey is not in the table "mongo.accounts__duplicate_authors"
@jthandy jthandy added this to the Archival Updates milestone Dec 13, 2016
@drewbanin drewbanin added the bug Something isn't working label Dec 13, 2016
@drewbanin
Copy link
Contributor

dbt tries to use the unique_key as the distkey. It also tries to use the updated_at field as the sortkey. This means that using an expression as the unique_key or updated_at definition will break archival. The solution here is to use the dbt_updated_at and scd_id fields directly instead of the expressions which are responsible for generating them

@jthandy
Copy link
Member Author

jthandy commented Dec 13, 2016

Oh. Yeah. Completely agree.

@drewbanin
Copy link
Contributor

#324

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants