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; } }
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; }
List<String> getPropSQLConstraint() { List<String> propSQLConstraint = new LinkedList<String>(); QueryTriple qt = planNode.getTriple(); // TODO [Property Path]: Double check with Mihaela that it is fine for // propTerm.toSqlDataString() to return null for complex path (ie., same behavior as variable) PropertyTerm propTerm = qt.getPredicate(); propSQLConstraint.add( hashColumnExpression(Constants.NAME_COLUMN_PREFIX_PREDICATE) + " = '" + propTerm.toSqlDataString() + "'"); return propSQLConstraint; }
/** @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; } }