File: 200_base_model.sql

package info (click to toggle)
sqlfmt 0.29.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,580 kB
  • sloc: python: 10,007; sql: 5,626; makefile: 39
file content (84 lines) | stat: -rw-r--r-- 2,451 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
with source as (select * from {{ source('my_application', 'users') }}),
  renamed as (

    select
      --ids
      id,
      nullif(xid,'') as xid,

      --date
      created_on,
      updated_on,

      nullif(email,'') as email,
      
      -- names
      nullif(full_name,'') as full_name,
      nullif(trim(
        case
          when regexp_count(nullif(full_name,''), ' ') = 0
            then nullif(full_name,'')
          when regexp_count(nullif(full_name,''), ' ') = 1
            then split_part(nullif(full_name,''), ' ', 1)
          else regexp_substr(nullif(full_name,''), '.* .* ') -- let's explain what is going on here
        end
      ), 'TEST_USER') as first_name,
      nullif(split_part(nullif(full_name,''), ' ', greatest(2, regexp_count(nullif(full_name,''), ' ')+1)),'') as last_name

    from

      source

    where

      nvl(is_deleted, false) is false
      and id <> 123456 -- a very long comment about why we would exclude this user from this table that we will not wrap

  )
select * from renamed
)))))__SQLFMT_OUTPUT__(((((
with
    source as (select * from {{ source("my_application", "users") }}),
    renamed as (

        select
            -- ids
            id,
            nullif(xid, '') as xid,

            -- date
            created_on,
            updated_on,

            nullif(email, '') as email,

            -- names
            nullif(full_name, '') as full_name,
            nullif(
                trim(
                    case
                        when regexp_count(nullif(full_name, ''), ' ') = 0
                        then nullif(full_name, '')
                        when regexp_count(nullif(full_name, ''), ' ') = 1
                        then split_part(nullif(full_name, ''), ' ', 1)
                        else regexp_substr(nullif(full_name, ''), '.* .* ')  -- let's explain what is going on here
                    end
                ),
                'TEST_USER'
            ) as first_name,
            nullif(
                split_part(
                    nullif(full_name, ''),
                    ' ',
                    greatest(2, regexp_count(nullif(full_name, ''), ' ') + 1)
                ),
                ''
            ) as last_name

        from source

        where nvl(is_deleted, false) is false and id <> 123456  -- a very long comment about why we would exclude this user from this table that we will not wrap

    )
select *
from renamed