Class Query

java.lang.Object
dev.roanh.gmark.query.Query
All Implemented Interfaces:
OutputFormal, OutputSQL, OutputXML

public class Query extends Object implements OutputSQL, OutputFormal, OutputXML
Represents a generated query with a number of projected variables and one or more query bodies.
  • Field Details

    • variables

      private List<Variable> variables
      The projected variables for this query (head, left hand side).
    • body

      private QueryBody body
      The body for this query.
  • Constructor Details

    • Query

      public Query(List<Conjunct> conjuncts, List<Variable> variables, Selectivity selectivity, QueryShape shape)
      Constructs a new query with a single body made up of the given list of conjuncts and with the given project variables, selectivity and shape.
      Parameters:
      conjuncts - The conjuncts for the query body.
      variables - The projected query variables.
      selectivity - The query body selectivity.
      shape - The query body shape.
    • Query

      public Query(QueryBody body, List<Variable> variables)
      Constructs a new query with a single body and with the given project variables, selectivity and shape.
      Parameters:
      body - The query body.
      variables - The projected query variables.
  • Method Details

    • getShape

      public QueryShape getShape()
      Gets the shape of this query.
      Returns:
      The query shape.
    • getSelectivity

      public Selectivity getSelectivity()
      Gets the selectivity of this query.
      Returns:
      The selectivity of this query.
    • getConjunctCount

      public int getConjunctCount()
      Gets the number of conjuncts in the query body with the most conjuncts.
      Returns:
      The maximum query body conjunct count.
    • isBinary

      public boolean isBinary()
      Checks if this query is binary. A query is binary when its arity is equal to 0.
      Returns:
      True if this query is binary.
    • getArity

      public int getArity()
      Gets the arity (number of projected variables) for this query.
      Returns:
      The arity for this query.
    • getBody

      public QueryBody getBody()
      Gets the query body for this query.
      Returns:
      The query body.
    • toFormalSyntax

      public String toFormalSyntax()
      Description copied from interface: OutputFormal
      Converts this object to its formal logic form.
      Specified by:
      toFormalSyntax in interface OutputFormal
      Returns:
      The formal representation of this object.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • writeXML

      public void writeXML(IndentWriter writer)
      Description copied from interface: OutputXML
      Writes this object as XML to the given writer.
      Specified by:
      writeXML in interface OutputXML
      Parameters:
      writer - The writer to write to.
    • writeSQL

      public void writeSQL(IndentWriter writer)
      Description copied from interface: OutputSQL
      Writes the SQL representation of this object to the given writer.
      Specified by:
      writeSQL in interface OutputSQL
      Parameters:
      writer - The writer to write to.
    • conjunctVarToSQL

      private static String conjunctVarToSQL(Variable v, Conjunct conj, Map<Conjunct,Integer> idMap)
      Converts a conjunct variable to SQL.
      Parameters:
      v - The variable to convert.
      conj - The conjunct this variable is a part of.
      idMap - A map storing the ID of each conjunct.
      Returns:
      The SQL version of this conjunct variable.