Skip to content

Commit

Permalink
Integrate skeleton of codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
AlSchlo committed Feb 11, 2025
2 parents 260e040 + 44d26e2 commit af45b32
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions optd-dsl/src/programs/working.optd
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Logical Filter(child: Logical, cond: Scalar) derive {
schema_len = input.schema_len
}


Logical Project(child: Logical, exprs: [Scalar]) derive {
schema_len = exprs.len
}
Expand All @@ -33,8 +32,6 @@ Logical Join(
}

// Rules

// memo(alexis): support member function for operators like apply_children
def rewrite_column_refs(predicate: Scalar, map: Map[Int64, Int64]): Scalar =
match predicate
case ColumnRef(idx) => ColumnRef(map(idx)),
Expand Down Expand Up @@ -80,25 +77,25 @@ def join_associate(expr: Logical): Logical =
)
else fail("")

def conjunctive_normal_form(expr: Scalar): Bool = fail("unimplemented")
@rule(Scalar)
def conjunctive_normal_form(expr: Scalar): Scalar = fail("unimplemented")

def with_optional_filter(key: String, old: Scalar, grouped: Map[String, [Scalar]]): Scalar = match grouped(key)
case Some(conds) => Filter(conds, old),
case _ => old
def with_optional_filter(key: String, old: Scalar, grouped: Map[String, [Scalar]]): Scalar =
match grouped(key)
case Some(conds) => Filter(conds, old),
case _ => old

@rule(Logical)
def filter_pushdown_join(expr: Logical): Logical =
match expr
case op @ Filter(Join(join_type, left, right, join_cond), cond) =>
val conditions_with_refs = conjunctive_normal_form(cond)
.map(c => (c, extract_column_refs(c)));

val grouped = conditions_with_refs.groupBy((cond, refs) => {
if has_refs_in_range(refs, 0, left.schema_len) &&
!has_refs_in_range(refs, left.schema_len, op.schema_len) then
val cnf = conjunctive_normal_form(cond);
val grouped = cnf.children.groupBy(cond => {
if has_refs_in_range(cond, 0, left.schema_len) &&
!has_refs_in_range(cond, left.schema_len, op.schema_len) then
"left"
else if !has_refs_in_range(refs, 0, left.schema_len) &&
has_refs_in_range(refs, left.schema_len, op.schema_len) then
else if !has_refs_in_range(cond, 0, left.schema_len) &&
has_refs_in_range(cond, left.schema_len, op.schema_len) then
"right"
else
"remain"
Expand Down

0 comments on commit af45b32

Please sign in to comment.