throws DatalogProgram2QueryConverterImpl.InvalidDatalogProgramException, IntermediateQueryBuilderException { AtomClassification classification = new AtomClassification(subAtomsOfTheJoin); if (classification.optionalGroupAtom.isPresent()) { throw new DatalogProgram2QueryConverterImpl.InvalidDatalogProgramException("GROUP atom found inside a LJ meta-atom");
throws DatalogProgram2QueryConverterImpl.InvalidDatalogProgramException, IntermediateQueryBuilderException { AtomClassification classification = new AtomClassification(atoms, datalogTools);
private static IntermediateQueryBuilder convertLeftJoinAtom(IntermediateQueryBuilder queryBuilder, QueryNode parentNodeOfTheLJ, List<Function> subAtomsOfTheLJ, Optional<ArgumentPosition> optionalPosition, Collection<Predicate> tablePredicates) throws DatalogProgram2QueryConverterImpl.InvalidDatalogProgramException, IntermediateQueryBuilderException { P2<List<Function>, List<Function>> decomposition = PullOutEqualityNormalizerImpl.splitLeftJoinSubAtoms(subAtomsOfTheLJ); final List<Function> leftAtoms = decomposition._1(); final List<Function> rightAtoms = decomposition._2(); /* * TODO: explain why we just care about the right */ AtomClassification rightSubAtomClassification = new AtomClassification(rightAtoms); Optional<ImmutableExpression> optionalFilterCondition = createFilterExpression( rightSubAtomClassification.booleanAtoms); LeftJoinNode ljNode = queryBuilder.getFactory().createLeftJoinNode(optionalFilterCondition); queryBuilder.addChild(parentNodeOfTheLJ, ljNode, optionalPosition); /* * Adds the left part */ queryBuilder = convertJoinAtom(queryBuilder, ljNode, leftAtoms, LEFT_POSITION, tablePredicates); /* * Adds the right part */ return convertDataOrCompositeAtoms(rightSubAtomClassification.dataAndCompositeAtoms, queryBuilder, ljNode, RIGHT_POSITION, tablePredicates); }
/** * TODO: describe */ public static IntermediateQuery convertDatalogRule(DBMetadata dbMetadata, CQIE datalogRule, Collection<Predicate> tablePredicates, Optional<ImmutableQueryModifiers> optionalModifiers, IntermediateQueryFactory iqFactory, ExecutorRegistry executorRegistry) throws DatalogProgram2QueryConverterImpl.InvalidDatalogProgramException { TargetAtom targetAtom = DatalogConversionTools.convertFromDatalogDataAtom(datalogRule.getHead()); DistinctVariableOnlyDataAtom projectionAtom = targetAtom.getProjectionAtom(); ConstructionNode rootNode = iqFactory.createConstructionNode(projectionAtom.getVariables(), targetAtom.getSubstitution(), optionalModifiers); List<Function> bodyAtoms = List.iterableList(datalogRule.getBody()); if (bodyAtoms.isEmpty()) { return createFact(dbMetadata, rootNode, projectionAtom, executorRegistry, iqFactory); } else { AtomClassification atomClassification = new AtomClassification(bodyAtoms); return createDefinition(dbMetadata, rootNode, projectionAtom, tablePredicates, atomClassification.dataAndCompositeAtoms, atomClassification.booleanAtoms, atomClassification.optionalGroupAtom, iqFactory, executorRegistry); } }
private IQTree convertLeftJoinAtom(List<Function> subAtomsOfTheLJ, Collection<Predicate> tablePredicates, IntermediateQueryFactory iqFactory) throws DatalogProgram2QueryConverterImpl.InvalidDatalogProgramException, IntermediateQueryBuilderException { P2<List<Function>, List<Function>> decomposition = pullOutEqualityNormalizer.splitLeftJoinSubAtoms(subAtomsOfTheLJ); final List<Function> leftAtoms = decomposition._1(); final List<Function> rightAtoms = decomposition._2(); /* * TODO: explain why we just care about the right */ AtomClassification rightSubAtomClassification = new AtomClassification(rightAtoms, datalogTools); Optional<ImmutableExpression> optionalFilterCondition = createFilterExpression( rightSubAtomClassification.booleanAtoms); LeftJoinNode ljNode = iqFactory.createLeftJoinNode(optionalFilterCondition); IQTree leftTree = convertAtoms(leftAtoms, tablePredicates, iqFactory); IQTree rightTree = convertAtoms(rightSubAtomClassification.dataAndCompositeAtoms, tablePredicates, iqFactory); return iqFactory.createBinaryNonCommutativeIQTree(ljNode, leftTree, rightTree); }
protected AtomClassification(List<Function> atoms) throws DatalogProgram2QueryConverterImpl.InvalidDatalogProgramException { dataAndCompositeAtoms = DatalogTools.filterDataAndCompositeAtoms(atoms); List<Function> otherAtoms = DatalogTools.filterNonDataAndCompositeAtoms(atoms); booleanAtoms = DatalogTools.filterBooleanAtoms(otherAtoms); if (dataAndCompositeAtoms.isEmpty()) throw new DatalogProgram2QueryConverterImpl.InvalidDatalogProgramException("No data or composite atom in " + atoms); optionalGroupAtom = extractOptionalGroupAtom(otherAtoms); /* * May throw a NotSupportedConversionException */ checkNonDataOrCompositeAtomSupport(otherAtoms, booleanAtoms, optionalGroupAtom); }
protected AtomClassification(List<Function> atoms, DatalogTools datalogTools) throws DatalogProgram2QueryConverterImpl.InvalidDatalogProgramException { dataAndCompositeAtoms = datalogTools.filterDataAndCompositeAtoms(atoms); List<Function> otherAtoms = datalogTools.filterNonDataAndCompositeAtoms(atoms); booleanAtoms = datalogTools.filterBooleanAtoms(otherAtoms); if (dataAndCompositeAtoms.isEmpty()) throw new DatalogProgram2QueryConverterImpl.InvalidDatalogProgramException("No data or composite atom in " + atoms); /* * May throw a NotSupportedConversionException */ checkNonDataOrCompositeAtomSupport(otherAtoms, booleanAtoms); }