Referencing the base table of a different model

Aberta
#5,900 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 4 dias

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
52/100
Tipo de issue
Funcionalidade
Clareza
Razoavelmente clara
Status de atividade
Pouca atividade
Stack de tecnologia
python, sql
Domínio
data-engineering

Direção de pesquisa

The issue points to the @resolve_template macro and the existing implementation for resolving the active model's base table, but names no source files or tests. Start by reading the implementation and tests for @resolve_template, then look for how other models are referenced. Done means a referenced model's base table can be retrieved without hardcoding its fingerprint.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

I have added primary keys into my SQLMesh models using https://github.com/SQLMesh/sqlmesh/issues/4568 as a guide. The @resolve_template macro is really useful for creating the key on the base table rather than the view.

I would also like to add some foreign keys but I don't think it's possible to get the base table for a different model. For example, this works by hardcoding the referenced table but it will break if the referenced model is ever rebuilt with a different fingerprint:

@IF( @runtime_stage = 'creating', ALTER TABLE @SQL('@this_model') ADD CONSTRAINT @resolve_template('FK_@{table_name}_id') FOREIGN KEY (id) REFERENCES schema._table__fingerprint (id) )

Is it possible to retrieve the base table from a different model in the same way that @resolve_template does for the active model?

Thanks

Linguagem predominante
Python
Estrelas
3.3k
Forks
471
Merge médio
6d 7h
PRs com merge (30d)
35

Preparar o ambiente

Abrir no Codespaces

Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de SQLMesh/sqlmesh

Todas as issues de SQLMesh/sqlmesh

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.