Skip to content

Instantly share code, notes, and snippets.

@gforsyth
Last active March 11, 2022 14:04
Show Gist options
  • Save gforsyth/1d41488a8680d2dd43bff8a07f1f7931 to your computer and use it in GitHub Desktop.
Save gforsyth/1d41488a8680d2dd43bff8a07f1f7931 to your computer and use it in GitHub Desktop.

repr

repr should be very fast repr should allow for recreation of the object but this may not be practical

make sure there is no usage of REPR as a lookup key anywhere

fix the ordering (r10 -> r09)

How many columns do we want to show if any?

There’s an obvious upper limit of some number N

Do we want to keep any tree representation?

For medium sized queries: yes – view of the structure is nice to have

For mega-query WTF do we do

Are mega-queries wide/deep or both?

More likely to be deep / long than to have any huge number of columns

Only show the columns that are projected that are different

Placeholder of ... for no changes? Only show columns in subsequent projections that differ from previous selection

repr max depth

Do we conk out at a certain depth / length?

Raw repr

r0 := AlchemyTable[part]
  p_partkey     int32!
  p_mfgr        string!
  p_type        string!
  p_size        int32!
  ...

r1 := AlchemyTable[partsupp]
  ps_partkey    int32!
  ps_suppkey    int32!
  ps_availqty   int32!
  ps_supplycost decimal(15, 2)?
  ...

r10 := Selection[r9]
  sort_keys:
    r9.s_acctbal.desc()
    r9.n_name
    r9.s_name
    r9.p_partkey

r2 := AlchemyTable[supplier]
  s_suppkey   int32!
  s_name      string!
  s_address   string!
  s_nationkey int32!
  s_phone     string!
  s_acctbal   decimal(15, 2)
  ...

r3 := AlchemyTable[nation]
  n_nationkey int32!
  n_name      string!
  n_regionkey int32!
  ...

r4 := AlchemyTable[region]
  r_regionkey int32!
  r_name      string!
  ...

r5 := InnerJoin[r0, r1] r0.p_partkey == r1.ps_partkey
  InnerJoin[..., r2] r2.s_suppkey == r1.ps_suppkey
  InnerJoin[..., r3] r2.s_nationkey == r3.n_nationkey
  InnerJoin[..., r4] r3.n_regionkey == r4.r_regionkey

r6 := InnerJoin[r1, r2] r2.s_suppkey == r1.ps_suppkey
  InnerJoin[..., r3] r2.s_nationkey == r3.n_nationkey
  InnerJoin[..., r4] r3.n_regionkey == r4.r_regionkey

r7 := Selection[r6]
  predicates:
    r6.r_name == 'EUROPE'
    r5.p_partkey == r6.ps_partkey

r8 := Selection[r5]
  predicates:
    r5.p_size == 25
    r5.p_type LIKE "%BRASS"
    r5.r_name == "EUROPE"
    r5.ps_supplycost == r7.ps_supplycost.min()

r9 := Selection[r8]
  selections[r8]:
    s_acctbal
    s_name
    n_name
    p_partkey
    p_mfgr
    s_address
    s_phone
    s_comment

Limit[r10, n=100]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment