Skip to content

Instantly share code, notes, and snippets.

@liancheng
Created March 14, 2016 04:02
Show Gist options
  • Save liancheng/d588d823f5fa8fca79ed to your computer and use it in GitHub Desktop.
Save liancheng/d588d823f5fa8fca79ed to your computer and use it in GitHub Desktop.
Scraper REPL session example
$ ./build/sbt repl/run
...
@ context range 10 groupBy 'id agg (count('id), 'id + 1) having ('id > 0 and count('id) > 0) explain ()
# Logical plan
Filter: condition=$0 ==> [?output?]
├╴$0: ((`id` > 0:INT) AND (COUNT(`id`) > 0:INT))
╰╴UnresolvedAggregate: keys=[$0], projectList=[$1, $2] ==> [?output?]
├╴$0: `id`
├╴$1: COUNT(`id`) AS ?alias?
├╴$2: (`id` + 1:INT) AS ?alias?
╰╴LocalRelation: data=<local-data> ==> [`id`#0:BIGINT!]
# Analyzed plan
Project: projectList=[$0, $1] ==> [`COUNT(id)`#1:BIGINT!, `(id + 1)`#2:BIGINT!]
├╴$0: `agg`#4:BIGINT! AS `COUNT(id)`#1
├╴$1: (`group`#3:BIGINT! + CAST(1:INT AS BIGINT)) AS `(id + 1)`#2
╰╴Filter: condition=$0 ==> [`group`#3:BIGINT!, `agg`#4:BIGINT!, `agg`#6:BIGINT!]
├╴$0: ((`group`#3:BIGINT! > CAST(0:INT AS BIGINT)) AND (`agg`#6:BIGINT! > CAST(0:INT AS BIGINT)))
╰╴Aggregate: keys=[$0], functions=[$1, $2] ==> [`group`#3:BIGINT!, `agg`#4:BIGINT!, `agg`#6:BIGINT!]
├╴$0: `id`#0:BIGINT! AS `group`#3
├╴$1: COUNT(`id`#0:BIGINT!) AS `agg`#4
├╴$2: COUNT(`id`#0:BIGINT!) AS `agg`#6
╰╴LocalRelation: data=<local-data> ==> [`id`#0:BIGINT!]
# Optimized plan
Project: projectList=[$0, $1] ==> [`COUNT(id)`#1:BIGINT!, `(id + 1)`#2:BIGINT!]
├╴$0: `agg`#4:BIGINT! AS `COUNT(id)`#1
├╴$1: (`group`#3:BIGINT! + 1:BIGINT) AS `(id + 1)`#2
╰╴Filter: condition=$0 ==> [`group`#3:BIGINT!, `agg`#4:BIGINT!, `agg`#6:BIGINT!]
├╴$0: (`agg`#6:BIGINT! > 0:BIGINT)
╰╴Aggregate: keys=[$0], functions=[$1, $2] ==> [`group`#3:BIGINT!, `agg`#4:BIGINT!, `agg`#6:BIGINT!]
├╴$0: `id`#0:BIGINT! AS `group`#3
├╴$1: COUNT(`id`#0:BIGINT!) AS `agg`#4
├╴$2: COUNT(`id`#0:BIGINT!) AS `agg`#6
╰╴Filter: condition=$0 ==> [`id`#0:BIGINT!]
├╴$0: (`id`#0:BIGINT! > 0:BIGINT)
╰╴LocalRelation: data=<local-data> ==> [`id`#0:BIGINT!]
# Physical plan
Project: expressions=[$0, $1] ==> [`COUNT(id)`#1:BIGINT!, `(id + 1)`#2:BIGINT!]
├╴$0: `agg`#4:BIGINT! AS `COUNT(id)`#1
├╴$1: (`group`#3:BIGINT! + 1:BIGINT) AS `(id + 1)`#2
╰╴Filter: condition=$0 ==> [`group`#3:BIGINT!, `agg`#4:BIGINT!, `agg`#6:BIGINT!]
├╴$0: (`agg`#6:BIGINT! > 0:BIGINT)
╰╴NotImplemented: logicalPlanName=Aggregate ==> [`group`#3:BIGINT!, `agg`#4:BIGINT!, `agg`#6:BIGINT!]
╰╴Filter: condition=$0 ==> [`id`#0:BIGINT!]
├╴$0: (`id`#0:BIGINT! > 0:BIGINT)
╰╴LocalRelation: data=<local-data> ==> [`id`#0:BIGINT!]
@ context range 10 as 'a join (context range 10 as 'b) on $"a.id" =:= $"b.id" show ()
╒══╤══╕
│id│id│
├──┼──┤
│ 0│ 0│
│ 1│ 1│
│ 2│ 2│
│ 3│ 3│
│ 4│ 4│
│ 5│ 5│
│ 6│ 6│
│ 7│ 7│
│ 8│ 8│
│ 9│ 9│
╘══╧══╛
@ context range 10 asTable "t"
@ "select id + 1, cast(id as string) from t".q show ()
╒════════╤══════════════════╕
│(id + 1)│CAST(id AS STRING)│
├────────┼──────────────────┤
│ 1│ 0│
│ 2│ 1│
│ 3│ 2│
│ 4│ 3│
│ 5│ 4│
│ 6│ 5│
│ 7│ 6│
│ 8│ 7│
│ 9│ 8│
│ 10│ 9│
╘════════╧══════════════════╛
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment