示例#1
0
 def __wrap_in_subquery(query_model):
     """
     create an outer query containing the variables, select columns, offset, limit, order,
     :param query_model:
     :return:
     """
     new_query_model = QueryModel()
     new_query_model.variables = copy.copy(query_model.variables)  # all prefixes are already in query_model1
     new_query_model.from_clause = copy.copy(query_model.from_clause)
     new_query_model.select_columns = copy.copy(query_model.select_columns)
     new_query_model.offset = query_model.offset
     new_query_model.limit = query_model.limit
     new_query_model.order_clause = copy.copy(query_model.order_clause)
     return new_query_model
示例#2
0
 def _outer_join(query_model1, query_model2):
     joined_query_model = QueryModel()
     joined_query_model.prefixes = copy.copy(
         query_model1.prefixes)  # all prefixes are already in query_model1
     joined_query_model.variables = copy.copy(
         query_model1.variables)  # all prefixes are already in query_model1
     joined_query_model.from_clause = copy.copy(query_model1.from_clause)
     joined_query_model.select_columns = copy.copy(
         query_model1.select_columns)
     joined_query_model.offset = query_model1.offset
     joined_query_model.limit = query_model1.limit
     joined_query_model.order_clause = copy.copy(query_model1.order_clause)
     QueryModel.clean_inner_qm(query_model1)
     QueryModel.clean_inner_qm(query_model2)
     joined_query_model.add_unions(query_model1)
     joined_query_model.add_unions(query_model2)
     return joined_query_model
示例#3
0
 def __join_expandable_grouped(self,
                               query_model1,
                               query_model2,
                               expandable_order=1):
     if self.join_type == JoinType.OuterJoin:  # outer join
         return JoinOperator._outer_join(query_model1, query_model2)
     elif self.join_type == JoinType.InnerJoin:
         # add query model 2 as a subquery
         QueryModel.clean_inner_qm(query_model2)
         query_model1.add_subquery(query_model2)
         return query_model1
     elif ((expandable_order == 1 and self.join_type == JoinType.LeftOuterJoin) or\
         (expandable_order == 2 and self.join_type == JoinType.RightOuterJoin)):
         # make the subquery optional
         QueryModel.clean_inner_qm(query_model2)
         query_model1.add_optional_subquery(query_model2)
         return query_model1
     elif ((expandable_order == 2 and self.join_type == JoinType.LeftOuterJoin) or\
         (expandable_order == 1 and self.join_type == JoinType.RightOuterJoin)):
         # create an outer query and add the main dataset as a subquery and the optional dataset as optional subquery
         joined_query_model = QueryModel()
         joined_query_model.prefixes = copy.copy(
             query_model1.prefixes
         )  # all prefixes are already in query_model1
         joined_query_model.variables = copy.copy(
             query_model1.variables
         )  # all prefixes are already in query_model1
         joined_query_model.from_clause = copy.copy(
             query_model1.from_clause)
         joined_query_model.select_columns = copy.copy(
             query_model1.select_columns)
         joined_query_model.offset = query_model1.offset
         joined_query_model.limit = query_model1.limit
         joined_query_model.order_clause = copy.copy(
             query_model1.order_clause)
         QueryModel.clean_inner_qm(query_model1)
         QueryModel.clean_inner_qm(query_model2)
         joined_query_model.add_optional_subquery(query_model1)
         joined_query_model.add_subquery(query_model2)
         return joined_query_model
     else:
         raise Exception("Undefined case")
示例#4
0
    def __join_grouped_grouped(self, query_model1, query_model2):
        joined_query_model = QueryModel()

        joined_query_model.prefixes = copy.copy(
            query_model1.prefixes)  # all prefixes are already in query_model1
        joined_query_model.add_prefixes(query_model2.prefixes)

        joined_query_model.variables = copy.copy(
            query_model1.variables.union(query_model2.variables)
        )  # all prefixes are already in query_model1
        joined_query_model.from_clause = copy.copy(query_model1.from_clause)
        joined_query_model.select_columns = copy.copy(
            query_model1.select_columns.union(query_model2.select_columns))
        joined_query_model.offset = min(query_model1.offset,
                                        query_model2.offset)
        joined_query_model.limit = max(query_model1.limit, query_model2.limit)
        query_model1.order_clause.update(query_model2.order_clause)
        joined_query_model.order_clause = copy.copy(query_model1.order_clause)

        QueryModel.clean_inner_qm(query_model1)
        QueryModel.clean_inner_qm(query_model2)

        # add subqueries
        if self.join_type == JoinType.InnerJoin:
            joined_query_model.add_subquery(query_model1)
            joined_query_model.add_subquery(query_model2)
        elif self.join_type == JoinType.LeftOuterJoin:
            joined_query_model.add_subquery(query_model1)
            joined_query_model.add_optional_subquery(query_model2)
        elif self.join_type == JoinType.RightOuterJoin:
            joined_query_model.add_subquery(query_model2)
            joined_query_model.add_optional_subquery(query_model1)
        else:  # outer join
            joined_query_model.add_unions(query_model1)
            joined_query_model.add_unions(query_model2)
        return joined_query_model