Github user zuyu commented on a diff in the pull request: https://github.com/apache/incubator-quickstep/pull/39#discussion_r68331825 --- Diff: query_optimizer/resolver/Resolver.cpp --- @@ -1528,6 +1618,89 @@ L::LogicalPtr Resolver::RenameOutputColumns( return L::Project::Create(logical_plan, project_expressions); } +E::WindowInfo Resolver::resolveWindow(const ParseWindow &parse_window, + const NameResolver &name_resolver) { + std::vector<E::AttributeReferencePtr> partition_by_attributes; + std::vector<E::AttributeReferencePtr> order_by_attributes; + std::vector<bool> order_by_directions; + std::vector<bool> nulls_first; + E::WindowFrameInfo *frame_info = nullptr; + + // Resolve PARTITION BY + if (parse_window.partition_by_expressions() != nullptr) { + for (const ParseExpression &unresolved_partition_by_expression : + *parse_window.partition_by_expressions()) { + ExpressionResolutionInfo expr_resolution_info( + name_resolver, + "PARTITION BY clause" /* clause_name */, + nullptr /* select_list_info */); + E::ScalarPtr partition_by_scalar = resolveExpression( + unresolved_partition_by_expression, + nullptr, // No Type hint. + &expr_resolution_info); + + if (partition_by_scalar->isConstant()) { + THROW_SQL_ERROR_AT(&unresolved_partition_by_expression) + << "Constant expression not allowed in PARTITION BY"; + } + + E::AttributeReferencePtr partition_by_attribute; + if (!E::SomeAttributeReference::MatchesWithConditionalCast(partition_by_scalar, + &partition_by_attribute)) { + THROW_SQL_ERROR_AT(&unresolved_partition_by_expression) + << "Only attribute name allowed in PARTITION BY in window definition"; + } + + partition_by_attributes.push_back(partition_by_attribute); + } + } + + // Resolve ORDER BY + if (parse_window.order_by_expressions() != nullptr) { + for (const ParseOrderByItem &order_by_item : + *parse_window.order_by_expressions()) { + ExpressionResolutionInfo expr_resolution_info( + name_resolver, + "ORDER BY clause" /* clause name */, + nullptr /* select_list_info */); + E::ScalarPtr order_by_scalar = resolveExpression( + *order_by_item.ordering_expression(), + nullptr, // No Type hint. + &expr_resolution_info); + + if (order_by_scalar->isConstant()) { + THROW_SQL_ERROR_AT(&order_by_item) + << "Constant expression not allowed in ORDER BY"; + } + + E::AttributeReferencePtr order_by_attribute; + if (!E::SomeAttributeReference::MatchesWithConditionalCast(order_by_scalar, + &order_by_attribute)) { + THROW_SQL_ERROR_AT(&order_by_item) + << "Only attribute name allowed in ORDER BY in window definition"; + } + + order_by_attributes.push_back(order_by_attribute); + order_by_directions.push_back(order_by_item.is_ascending()); + nulls_first.push_back(order_by_item.nulls_first()); + } + } + + // Resolve window frame + if (parse_window.frame_info() != nullptr) { + const quickstep::ParseFrameInfo *parse_frame_info = parse_window.frame_info(); + frame_info = new E::WindowFrameInfo(parse_frame_info->is_row, + parse_frame_info->num_preceding, + parse_frame_info->num_following); --- End diff -- Please align with `(` in Line `1692`.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---