Skip to content

Instantly share code, notes, and snippets.

@gforsyth
Last active March 11, 2022 14:04
Show Gist options
  • Select an option

  • Save gforsyth/1d41488a8680d2dd43bff8a07f1f7931 to your computer and use it in GitHub Desktop.

Select an option

Save gforsyth/1d41488a8680d2dd43bff8a07f1f7931 to your computer and use it in GitHub Desktop.

Revisions

  1. gforsyth revised this gist Mar 11, 2022. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions scratch.org
    Original file line number Diff line number Diff line change
    @@ -34,7 +34,7 @@ Do we conk out at a certain depth / length?

    * Raw repr

    #+BEGIN_VERSE
    #+BEGIN_SRC

    r0 := AlchemyTable[part]
    p_partkey int32!
    @@ -111,4 +111,4 @@ r9 := Selection[r8]

    Limit[r10, n=100]

    #+END_VERSE
    #+END_SRC
  2. gforsyth created this gist Mar 11, 2022.
    114 changes: 114 additions & 0 deletions scratch.org
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,114 @@
    #+TITLE: repr


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

    * TODO make sure there is no usage of REPR as a lookup key anywhere
    DEADLINE: <2022-03-11 Fri>

    * TODO 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

    #+BEGIN_VERSE

    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]

    #+END_VERSE