{
  head:{
    type:"APACHE_DRILL_LOGICAL",
    version:"1",
    generator:{
      type:"manual",
      info:"na"
    }
  },
  storage:{
    console: {type: "console"},
    fs1: {type: "fs", root:"file:///"},
    cp: {type: "classpath"}
  },
  query:[
    {
      op:"sequence",
      do:[
	    {
	      op: "scan",
	      memo: "initial_scan",
	      ref: "donuts",
	      storageengine: "cp",
	      selection: {
	        path: "/donuts.json",
	        type: "JSON"
	      }
	    },
        {
	      op: "transform",
	      transforms: [
	        { ref: "quantity", expr: "donuts.sales"}
	      ]
	    },
	    {
	      op: "filter",
	      expr: "donuts.ppu < 1.00"
	    }, 
	    {
	      op: "segment",
	      ref: "ppusegment",
	      exprs: ["donuts.ppu"]
	    },
	    {
	      op: "collapsingaggregate",
	      within: "ppusegment",
	      carryovers: ["donuts.ppu"], 
	      aggregations: [
	        { ref: "donuts.typeCount",  expr: "count(1)" },
	        { ref: "donuts.quantity",  expr: "sum(quantity)" },
	        { ref: "donuts.sales",  expr: "sum(donuts.ppu * quantity)" }
	      ]
	    },
	    {
	      op: "order",
	      orderings: [
	        {order: "DESC", expr: "donuts.ppu" }
	      ]
	    }, 
	    {
	      op: "project",
	      projections: [
	        { ref: "output", expr: "donuts" }
	      ]
	    },
 	    {
          op: "limit",
          first: 0,
          last: 100
        }, 
	    {
	      op: "store",
	      memo: "output sink",
	      storageengine: "console",
	      target: {pipe: "STD_OUT"}
	    }
      ]
    }
  ]
}

