quickstep-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zuyu <...@git.apache.org>
Subject [GitHub] incubator-quickstep pull request #229: Implement parser and resolver for UNI...
Date Fri, 07 Apr 2017 02:17:26 GMT
Github user zuyu commented on a diff in the pull request:

    https://github.com/apache/incubator-quickstep/pull/229#discussion_r110304313
  
    --- Diff: query_optimizer/resolver/Resolver.cpp ---
    @@ -1350,16 +1351,172 @@ L::LogicalPtr Resolver::resolveSelect(
       return logical_plan;
     }
     
    +L::LogicalPtr Resolver::resolveSetOperations(
    +    const ParseSetOperation &parse_set_operations,
    +    const std::string &set_operation_name,
    +    const std::vector<const Type*> *type_hints,
    +    const NameResolver *parent_resolver) {
    +  std::vector<const ParseSetOperation*> operands;
    +  CollapseSetOperation(parse_set_operations, parse_set_operations, &operands);
    +
    +  DCHECK_LT(1u, operands.size());
    +  std::vector<L::LogicalPtr> resolved_operations;
    +  std::vector<std::vector<E::AttributeReferencePtr>> attribute_matrix;
    +
    +  // Resolve the first operation, and get the output attributes.
    +  auto iter = operands.begin();
    +  const ParseSetOperation &operation = static_cast<const ParseSetOperation&>(**iter);
    +  L::LogicalPtr operation_logical =
    +      resolveSetOperationDispatcher(operation, set_operation_name, type_hints, parent_resolver);
    +  const std::vector<E::AttributeReferencePtr> operation_attributes =
    +      operation_logical->getOutputAttributes();
    +  attribute_matrix.push_back(operation_attributes);
    +  resolved_operations.push_back(operation_logical);
    +
    +  // Resolve the rest operations, and check the size of output attributes.
    +  ++iter;
    +  for (; iter != operands.end(); ++iter) {
    +    const ParseSetOperation &current_operation =
    +        static_cast<const ParseSetOperation&>(**iter);
    +    L::LogicalPtr current_logical =
    +        resolveSetOperationDispatcher(current_operation, set_operation_name, type_hints,
parent_resolver);
    +    attribute_matrix.emplace_back(current_logical->getOutputAttributes());
    +
    +    // Check output attributes size.
    +    // Detailed type check and type cast will perform later.
    +    if (attribute_matrix.back().size() != operation_attributes.size()) {
    +        THROW_SQL_ERROR_AT(&current_operation)
    +            << "Can not perform " << parse_set_operations.getName()
    +            << "opeartion between " << std::to_string(attribute_matrix.back().size())
    +            << "and " << std::to_string(operation_attributes.size())
    +            << "columns";
    +    }
    +
    +    resolved_operations.push_back(current_logical);
    +  }
    +
    +  // Get the possible output attributes that the attributes of all operands can cast
to.
    +  std::vector<E::AttributeReferencePtr> possible_attributes;
    +  for (std::size_t aid = 0; aid < operation_attributes.size(); ++aid) {
    +    E::AttributeReferencePtr possible_attribute = attribute_matrix[0][aid];
    +    for (std::size_t opid = 1; opid < resolved_operations.size(); ++opid) {
    +      const Type &current_type = attribute_matrix[opid][aid]->getValueType();
    +      const Type &possible_type = possible_attribute->getValueType();
    +      if (!possible_type.equals(current_type)) {
    +        if (possible_type.getSuperTypeID() == Type::SuperTypeID::kNumeric &&
    +            current_type.getSuperTypeID() == Type::SuperTypeID::kNumeric) {
    +          if (possible_type.isSafelyCoercibleFrom(current_type)) {
    +            // Cast current_type to possible_type.
    +            // Possible_attribute remain the same, nothing needs to change.
    +          } else if (current_type.isSafelyCoercibleFrom(possible_type)) {
    +            // Cast possible_type to current_type.
    +            possible_attribute = attribute_matrix[opid][aid];
    +          } else {
    +            // Can not cast between possible_type and current_type.
    +            // Throw an SQL error.
    +            THROW_SQL_ERROR_AT(&parse_set_operations)
    +                << "There is not a safely coerce between "
    +                << current_type.getName()
    +                << "and " << possible_type.getName();
    +          }
    +        } else {
    +            THROW_SQL_ERROR_AT(&parse_set_operations)
    --- End diff --
    
    Reduce to two-whitespace-indentation.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message