Skip to content

Instantly share code, notes, and snippets.

View prateeka's full-sized avatar

Prateek Asthana prateeka

View GitHub Profile
@prateeka
prateeka / corelatedQuery.sql
Last active November 9, 2020 17:56
sql corelated queries for Lag, FirstChild, FirstSibling
* Firstchild
SELECT
f,
l
FROM
( SELECT
firstname f,
( SELECT
lastname l
FROM
@prateeka
prateeka / data_setup.sql
Last active November 26, 2020 01:26
data_setup for country, states, orders
drop table country;
drop table states;
drop table sales;
CREATE TABLE
IF NOT EXISTS country
(
country_id INTEGER IDENTITY(1,1) ,
_name VARCHAR(22) NOT NULL,
UNIQUE ( _name)
@prateeka
prateeka / siblingMapping.sql
Last active November 26, 2020 01:15
FirstSibling mapping table query
-- firstSibling sub-level
SELECT st.id orig_id, rk.id mapped_id
FROM (select country_id, id, RANK() over (ORDER BY country_id) _rank from states) st
join (SELECT country_id, id, ROW_NUMBER() over (ORDER BY country_id asc , id asc ) rownumb FROM states) rk
on st._rank = rk.rownumb and rk.country_id = st.country_id;
-- lastSibling sub-level
SELECT st.id orig_id, rk.id mapped_id
FROM (select country_id, id, RANK() over (ORDER BY country_id) _rank from states) st
@prateeka
prateeka / firstChild_bug.sql
Created November 27, 2020 06:21
sql for firstChild calculating measure at "targetLevel" instead of "firstChild" level
SELECT
MIN(t_117.c0) AS c0,
MIN(t_117.c_51) AS c1,
t_117.c2 AS c2,
t_117.c3s0 AS c3s0
FROM
(
SELECT
MIN(t_116.c0) AS c0,
MIN(t_116.c_51) AS c_51,
@prateeka
prateeka / firstChild_bug.json
Created November 27, 2020 06:25
virtualCube for firstChild calculating measure at "targetLevel" instead of "firstChild" level
OrderCube(
AggregateLogical(
SelectedData(
ColumnData(SelectColumn(Some(c0),AttributeValue(FlatAttribute(62874bbe-7ead-48ac-4496-8c7758b5aaa8: "orderquantity1")),Sum), Sum, Some(c0)),
ColumnData(SelectColumn(Some(c1),DimensionallyModifiedValue(AggregatedValue(AttributeValue(FlatAttribute(62874bbe-7ead-48ac-4496-8c7758b5aaa8: "orderquantity1")),Sum),List(Child(CurrentMember(FlatHierarchy(9bf44374-c106-4ab3-9c6a-d68474e9b25f+3938: "Product Dimension")),true))),NoAggregation), NoAggregation, Some(c1)),
ColumnData(SelectColumn(Some(c2),AttributeValue(FlatAttribute(2ff18d3a-894a-4be1-6d5c-39d97245160a: "Product Line")),AggregateGrouped(true)), AggregateGrouped(true), Some(c2)),
ColumnData(SelectColumn(Some(c3s0),KeyValue(FlatKey(3b0e5176-ca31-4706-a508-092e3c17daa2)),AggregateGrouped(true)), AggregateGrouped(true), Some(c3s0))
),
AuxiliaryData(),
UnionCubes(
@prateeka
prateeka / console_1.sql
Created December 4, 2020 06:08
firstChild.name encountering sql group-by error.
SELECT
MIN(t_101.c_44) AS c0,
t_101.c1 AS c1,
t_101.c2s0 AS c2s0
FROM
(
SELECT
MIN(t_98.c_44) AS c_44,
COALESCE(t_100.c_45, t_98.c1) AS c1,
COALESCE(t_100.c_55, t_98.c2s0) AS c2s0
@prateeka
prateeka / console_1.sql
Last active December 6, 2020 19:22
'All' level selecting 'min' member instead of 'firstChild' member
SELECT
MIN(t_129.c0) AS c0,
MIN(t_129.c_39) AS c1,
t_129.c2 AS c2,
t_129.c3s0 AS c3s0
FROM
(
SELECT
MIN(t_128.c0) AS c0,
MIN(t_128.c_39) AS c_39,
@prateeka
prateeka / CalculationResolver.scala
Last active July 5, 2021 19:26
DistinctCount additionDistinctCount addition
case MdxFunctions.DistinctCount.Applied(valueSet :: HNil) =>
val resolvedVal = ConstantValue(5, IntType)
ComplexAggregatedValue(resolvedVal, resolveSetExpression(valueSet), core.DistinctCountExact)
@prateeka
prateeka / GraphPlanner.scala
Last active July 30, 2021 23:16
AggLogical-lastchild.lastchild-fail
AggregateLogical(
SelectedData(
ColumnData(SelectColumn(Some(c0),DimensionallyModifiedValue(AggregatedValue(AttributeValue(FlatAttribute(ef1dd654-da9a-42bc-77ef-ea4431bdeb4e: "salesamount1")),Sum),List(Child(Child(CurrentMember(FlatHierarchy(d525ca44-1aa7-4c19-bfa7-ed6e69040b00+1298889108: "Order Date Month Hierarchy")),false),false))),NoAggregation), NoAggregation, Some(c0))
),
AuxiliaryData(),
AggregateLogical(
SelectedData(
DimensionallyModifiedData(ValueData(AggregatedValue(AttributeValue(FlatAttribute(ef1dd654-da9a-42bc-77ef-ea4431bdeb4e: "salesamount1")),Sum),NoAggregation,Set(RawAttribute(FlatAttribute(ef1dd654-da9a-42bc-77ef-ea4431bdeb4e: "salesamount1"),Sum,Some(c_36))),Some(c_37)),List(Child(Child(CurrentMember(FlatHierarchy(d525ca44-1aa7-4c19-bfa7-ed6e69040b00+1298889108: "Order Date Month Hierarchy")),false),false)),Min,Some(c_37))
),
AuxiliaryData(),
@prateeka
prateeka / SqlLanguage.scala
Last active September 18, 2021 10:45
atscale-4654: missing group-by clause in outbound query. reason for missing the group-by clause for the ticket are listed here compared to other cases which have group-by clause
def makeSelectColumn(gb: GroupByType): Option[SelectColumn] = {
gb match {
case GroupByIgnore => None
case _: GroupByColumnNumber => None
case gbv@GroupByValue(_: ConstantValue, _) if findGroupByTypeColumn(gbv).isEmpty => None
case _ =>
val (exposed, expr) =
gb match {
case GroupByColumnName(name, _, Some(expression)) => (Some(name), expression)
case GroupByValue(_, expression) => (None, expression)