List<String> mapEntryForProject() {
   QueryTriple qt = planNode.getTriple();
   QueryTripleTerm entryTerm = null;
   AccessMethod am = planNode.getMethod();
   boolean entryHasSqlType = false;
   if (AccessMethodType.isDirectAccess(am.getType())) {
     entryTerm = qt.getSubject();
   } else {
     entryTerm = qt.getObject();
     entryHasSqlType = true;
   }
   if (entryTerm.isVariable()) {
     Variable entryVariable = entryTerm.getVariable();
     if (projectedInPrimary.contains(entryVariable)) return null;
     projectedInPrimary.add(entryVariable);
     List<String> entrySqlToSparql = new LinkedList<String>();
     entrySqlToSparql.add(Constants.NAME_COLUMN_ENTRY + " AS " + entryVariable.getName());
     String entryTypeSql = null;
     Set<Variable> iriBoundVariables = wrapper.getIRIBoundVariables();
     if (!iriBoundVariables.contains(entryVariable)) {
       entryTypeSql =
           (entryHasSqlType)
               ? Constants.NAME_COLUMN_PREFIX_TYPE
               : new Short(TypeMap.IRI_ID).toString();
       entrySqlToSparql.add(
           entryTypeSql
               + " AS "
               + entryVariable.getName()
               + Constants.TYP_COLUMN_SUFFIX_IN_SPARQL_RS);
     }
     return entrySqlToSparql;
   } else {
     return null;
   }
 }
 /**
  * This is used to compute the predicate or value columns in the PH tables Deals with multiple
  * hash functions
  *
  * @param columnName
  * @return
  */
 private String hashColumnExpression(String columnName) {
   String predicateString = planNode.getTriple().getPredicate().toString();
   PredicateTable hashingFamily = null;
   AccessMethod am = planNode.getMethod();
   if (AccessMethodType.isDirectAccess(am.getType())) {
     hashingFamily = store.getDirectPredicates();
   } else {
     hashingFamily = store.getReversePredicates();
   }
   int numberOfPredHashes = hashingFamily.getHashCount(predicateString);
   if (numberOfPredHashes == 0) {
     return null;
   } else if (numberOfPredHashes
       == 1 /*&& (mergeLogicType != SQLLogicNodeType.AND || !tapn.hasPossibleSpills(store))*/) {
     String pExpression = "T." + columnName + hashingFamily.getHashes(predicateString)[0];
     return pExpression;
   } else {
     MonitoredStringBuffer tmpProjectString = new MonitoredStringBuffer(" CASE ");
     for (int h = 0; h < numberOfPredHashes; h++) {
       int hash = hashingFamily.getHashes(predicateString)[h];
       if (hash == -1) {
         hash = 0;
       }
       readPredicateColumn(predicateString, tmpProjectString, hash, columnName);
       if (hashingFamily.getHashes(predicateString)[0] == -1) {
         break;
       }
     }
     tmpProjectString.append(" ELSE NULL END");
     return tmpProjectString.toString();
   }
 }
 private List<String> getEntrySQLConstraint() {
   List<String> entrySQLConstraint = new LinkedList<String>();
   QueryTriple qt = planNode.getTriple();
   QueryTripleTerm entryTerm = null;
   AccessMethod am = planNode.getMethod();
   boolean hasSqlType = false;
   if (AccessMethodType.isDirectAccess(am.getType())) {
     entryTerm = qt.getSubject();
   } else {
     entryTerm = qt.getObject();
     hasSqlType = true;
   }
   if (entryTerm.isVariable()) {
     Variable entryVariable = entryTerm.getVariable();
     PlanNode predecessor = planNode.getPredecessor(wrapper.getPlan());
     boolean typConstraint = false;
     if (hasSqlType && wrapper.getIRIBoundVariables().contains(entryVariable)) {
       entrySQLConstraint.add(
           getTypeConstraintForIRIs(tTableColumnPrefix + Constants.NAME_COLUMN_PREFIX_TYPE));
     } else if (hasSqlType && !wrapper.getIRIBoundVariables().contains(entryVariable)) {
       typConstraint = true;
     }
     boolean entryConstraintWithPredecessor =
         getPredecessorConstraint(
             entrySQLConstraint,
             entryVariable,
             predecessor,
             tTableColumnPrefix + Constants.NAME_COLUMN_ENTRY,
             tTableColumnPrefix + Constants.NAME_COLUMN_PREFIX_TYPE,
             typConstraint);
     if (!entryConstraintWithPredecessor) {
       // Check for entry constraint for variable with the same name on different positions
       if (varMap.containsKey(entryVariable.getName())) {
         entrySQLConstraint.add(
             tTableColumnPrefix
                 + Constants.NAME_COLUMN_ENTRY
                 + " = "
                 + varMap.get(entryVariable.getName()).fst);
       }
     }
     String entryType =
         (typConstraint) ? tTableColumnPrefix + Constants.NAME_COLUMN_PREFIX_TYPE : null;
     varMap.put(
         entryVariable.getName(),
         Pair.make(tTableColumnPrefix + Constants.NAME_COLUMN_ENTRY, entryType));
   } else {
     super.addConstantEntrySQLConstraint(
         entryTerm,
         entrySQLConstraint,
         hasSqlType,
         tTableColumnPrefix + Constants.NAME_COLUMN_ENTRY);
   }
   return entrySQLConstraint;
 }
 List<String> getValueSQLConstraint() {
   List<String> valueSQLConstraint = new LinkedList<String>();
   QueryTriple qt = planNode.getTriple();
   QueryTripleTerm valueTerm = null;
   AccessMethod am = planNode.getMethod();
   boolean hasSqlType = false;
   if (AccessMethodType.isDirectAccess(am.getType())) {
     valueTerm = qt.getObject();
     hasSqlType = true;
   } else {
     valueTerm = qt.getSubject();
   }
   if (valueTerm.isVariable()) {
     Variable valueVariable = valueTerm.getVariable();
     PlanNode predecessor = planNode.getPredecessor(wrapper.getPlan());
     boolean typConstraint = false;
     if (hasSqlType && wrapper.getIRIBoundVariables().contains(valueVariable)) {
       valueSQLConstraint.add(
           getTypeConstraintForIRIs(hashColumnExpression(Constants.NAME_COLUMN_PREFIX_TYPE)));
     }
     if (hasSqlType && !wrapper.getIRIBoundVariables().contains(valueVariable)) {
       typConstraint = true;
     }
     boolean hasValueConstrintWithPredecessor =
         getPredecessorConstraint(
             valueSQLConstraint,
             valueVariable,
             predecessor,
             hashColumnExpression(Constants.NAME_COLUMN_PREFIX_VALUE),
             hashColumnExpression(Constants.NAME_COLUMN_PREFIX_TYPE),
             typConstraint);
     if (!hasValueConstrintWithPredecessor) {
       if (varMap.containsKey(valueVariable.getName())) {
         // Check for value constraint for variable with the same name on different positions
         valueSQLConstraint.add(
             hashColumnExpression(Constants.NAME_COLUMN_PREFIX_VALUE)
                 + " = "
                 + varMap.get(valueVariable.getName()).fst);
       }
     }
     String valueType =
         (typConstraint) ? hashColumnExpression(Constants.NAME_COLUMN_PREFIX_TYPE) : null;
     varMap.put(
         valueVariable.getName(),
         Pair.make(hashColumnExpression(Constants.NAME_COLUMN_PREFIX_VALUE), valueType));
   } else {
     valueSQLConstraint.add(
         hashColumnExpression(Constants.NAME_COLUMN_PREFIX_VALUE)
             + " = '"
             + valueTerm.toSqlDataString()
             + "'");
   }
   return valueSQLConstraint;
 }
 /** @return */
 List<String> mapValForProject() {
   QueryTriple qt = planNode.getTriple();
   QueryTripleTerm valTerm = null;
   AccessMethod am = planNode.getMethod();
   PredicateTable predicateTable = null;
   boolean valueHasSqlType = false;
   if (AccessMethodType.isDirectAccess(am.getType())) {
     valTerm = qt.getObject();
     valueHasSqlType = true;
     predicateTable = store.getDirectPredicates();
   } else {
     valTerm = qt.getSubject();
     predicateTable = store.getReversePredicates();
   }
   if (valTerm.isVariable()) {
     Variable valueVariable = valTerm.getVariable();
     Db2Type pType = predicateTable.getType(qt.getPredicate().getIRI().getValue());
     wrapper.addProperyValueType(valueVariable.getName(), pType);
     if (projectedInPrimary.contains(valueVariable)) return null;
     projectedInPrimary.add(valueVariable);
     List<String> valSqlToSparql = new LinkedList<String>();
     valSqlToSparql.add(
         hashColumnExpression(Constants.NAME_COLUMN_PREFIX_VALUE)
             + " AS "
             + valueVariable.getName());
     String valSqlType = null;
     Set<Variable> iriBoundVariables = wrapper.getIRIBoundVariables();
     if (!iriBoundVariables.contains(valueVariable)) {
       valSqlType =
           (valueHasSqlType)
               ? hashColumnExpression(Constants.NAME_COLUMN_PREFIX_TYPE)
               : new Short(TypeMap.IRI_ID).toString();
       valSqlToSparql.add(
           valSqlType
               + " AS "
               + valueVariable.getName()
               + Constants.TYP_COLUMN_SUFFIX_IN_SPARQL_RS);
     }
     return valSqlToSparql;
   } else {
     return null;
   }
 }