Skip to content

Commit

Permalink
Makes the generated SQL for a query use a sensible column name
Browse files Browse the repository at this point in the history
than just column_0 and _1, etc.
  • Loading branch information
netj committed Jan 31, 2016
1 parent 0e1d839 commit 97d6603
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/main/scala/org/deepdive/ddlog/DeepDiveLogCompiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ object AliasStyle extends Enumeration {
type AliasStyle = Value
// TableStyle: tableName.R{tableIndex}.columnName
// ViewStyle: column_{columnIndex}
val ViewAlias, TableAlias, NoAlias = Value
val ViewAlias, TableAlias, NoAlias, UseVariableAsAlias = Value
}
import AliasStyle._

Expand Down Expand Up @@ -346,6 +346,7 @@ class QueryCompiler(cq : ConjunctiveQuery, ss: CompilationState) {
case _ => s" AS column_${cq.headTerms indexOf e}"
}
case ViewAlias => s" AS column_${cq.headTerms indexOf e}"
case UseVariableAsAlias => s""" AS "${DeepDiveLogPrettyPrinter.print(e)}""""
}

// resolve an expression
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object DeepDiveLogQueryCompiler extends DeepDiveLogHandler {
qc.generateSQL(AliasStyle.ViewAlias)}"""
}) ++ List({
// compile the query
s"""${new QueryCompiler(query, compilationState).generateSQL()}"""
s"""${new QueryCompiler(query, compilationState).generateSQL(AliasStyle.UseVariableAsAlias)}"""
}) mkString(";\n\n")
println(sql)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SELECT COUNT(R0.relation_id) AS column_0
SELECT COUNT(R0.relation_id) AS "COUNT(r)"
FROM has_spouse R0

0 comments on commit 97d6603

Please sign in to comment.