New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify grounding by removing joins with var ID tables #110
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,8 +116,9 @@ class DeepDiveLogCompiler( program : DeepDiveLog.Program, config : DeepDiveLog.C | |
// odd has happened. | ||
def resolveName( v : Variable ) : String = { | ||
v match { case Variable(v,relName,i) => | ||
if(attrNameForRelationAndPosition contains (relName,i)) { | ||
attrNameForRelationAndPosition(relName,i) | ||
val realRel = relName.replaceAll("^" + deepdivePrefixForVariablesWithIdsTable, "") | ||
if(attrNameForRelationAndPosition contains (realRel,i)) { | ||
attrNameForRelationAndPosition(realRel,i) | ||
} else { | ||
// for views, columns names are in the form of "column_index" | ||
return s"column_${i}" | ||
|
@@ -511,7 +512,7 @@ class QueryCompiler(cq : ConjunctiveQuery, hackFrom: List[String] = Nil, hackWhe | |
case (x: Atom, i) if schemaDeclarationByRelationName get x.name exists (_.isQuery) => | ||
// TODO maybe TableAlias can be useful here or we can completely get rid of it? | ||
// variable id column | ||
s"""${deepdiveVariableIdColumn}_${headAsBody indexOf x}.${ | ||
s"""R${headAsBody indexOf x}.${ | ||
deepdiveVariableIdColumn | ||
} AS "${x.name}.R${headAsBody indexOf x}.${deepdiveVariableIdColumn}\"""" :: ( | ||
// project variable key columns as well (to reduce unnecssary joins) | ||
|
@@ -530,35 +531,22 @@ class QueryCompiler(cq : ConjunctiveQuery, hackFrom: List[String] = Nil, hackWhe | |
case _ => List.empty | ||
} | ||
|
||
val internalVarTables = headAsBody.zipWithIndex flatMap { | ||
case (x: Atom, i) if schemaDeclarationByRelationName get x.name exists (_.isQuery) => | ||
List(s"""${deepdivePrefixForVariablesIdsTable}${x.name} AS ${deepdiveVariableIdColumn}_${headAsBody indexOf x}""") | ||
case _ => List.empty | ||
val headAsBodyWithIds = headAsBody map { | ||
case(x: Atom) => Atom(s"""${deepdivePrefixForVariablesWithIdsTable}${x.name}""", x.terms) | ||
} | ||
|
||
val internalVarJoinConds = headAsBody.zipWithIndex flatMap { | ||
case (x: Atom, i) if schemaDeclarationByRelationName get x.name exists (_.isQuery) => | ||
List( | ||
// project variable key columns as well (to reduce unnecssary joins) | ||
schemaDeclarationByRelationName get x.name map (_.keyColumns map { | ||
case term => s"""R${headAsBody indexOf x}.${term} = ${deepdiveVariableIdColumn}_${headAsBody indexOf x}.${term}""" | ||
}) get | ||
) | ||
case _ => List.empty | ||
} flatten | ||
|
||
var nonCategoryWeightCols = new HashSet[String]() | ||
|
||
val inputQueries = | ||
stmt.q.bodies map { case cqBody => | ||
// Here we need to select from the bodies atoms as well as the head atoms, | ||
// which are the variable relations. | ||
// This is achieved by puting head atoms into the body. | ||
val fakeBody = headAsBody ++ cqBody | ||
val fakeBody = headAsBodyWithIds ++ cqBody | ||
val fakeCQ = stmt.q.copy(bodies = List(fakeBody)) | ||
|
||
// TODO XXX: Fix the `internal` hack below | ||
val qc = new QueryCompiler(fakeCQ, internalVarTables, internalVarJoinConds) | ||
val qc = new QueryCompiler(fakeCQ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you remove the TODO XXX comment since they're gone now? |
||
|
||
// weight columns | ||
val weightColumns = stmt.weights.variables.zipWithIndex collect { | ||
|
@@ -685,7 +673,7 @@ object DeepDiveLogCompiler extends DeepDiveLogHandler { | |
val deepdiveVariableIdColumn = "dd_id" | ||
val deepdiveVariableLabelColumn = "dd_label" | ||
val deepdiveVariableLabelTruthinessColumn = "dd_truthiness" | ||
val deepdivePrefixForVariablesIdsTable = "dd_variables_" | ||
val deepdivePrefixForVariablesWithIdsTable = "dd_predicate_" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, could you elaborate a bit on the naming of this table? "predicate" isn't very intuitive IMO. I think it's still a materialized variable, so maybe something straightforward as |
||
|
||
// entry point for compilation | ||
override def run(parsedProgram: DeepDiveLog.Program, config: DeepDiveLog.Config) = { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not comfortable with stitching regex like this.. Looks like
stripPrefix
will do a cleaner job?