http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/parser/ParseIndexProperties.hpp ---------------------------------------------------------------------- diff --git a/parser/ParseIndexProperties.hpp b/parser/ParseIndexProperties.hpp deleted file mode 100644 index 1ff13be..0000000 --- a/parser/ParseIndexProperties.hpp +++ /dev/null @@ -1,512 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -#ifndef QUICKSTEP_PARSER_PARSE_INDEX_PROPERTIES_HPP_ -#define QUICKSTEP_PARSER_PARSE_INDEX_PROPERTIES_HPP_ - -#include <cstdint> -#include <memory> -#include <string> -#include <vector> -#include <unordered_map> - -#include "parser/ParseKeyValue.hpp" -#include "parser/ParseString.hpp" -#include "parser/ParseTreeNode.hpp" -#include "storage/StorageBlockLayout.pb.h" -#include "utility/Macros.hpp" -#include "utility/PtrList.hpp" -#include "utility/StringUtil.hpp" - -#include "glog/logging.h" - -namespace quickstep { -/** \addtogroup Parser - * @{ - */ - -/** - * @brief Base class for different types of indices and their associated properties - */ -class IndexProperties { - public: - typedef std::unordered_map<const char*, ParseKeyValue::KeyValueType> valid_property_map_type; - - // An enum specifying the reason for an invalid index description, if any. - enum class InvalidIndexType { - kNone = 0, - kUnimplemented, - kDuplicateKey, - kInvalidKey, - kInvalidValue, - kTypeIsNotString, - kSizeIsFloat, - kSizeIsNegative, - kNumHashesIsFloat, - kNumHashesIsNegative, - kProjectedCountIsFloat, - kProjectedCountIsNegative - }; - - /** - * @brief Constructor. - * @note The constructor takes ownership of index_sub_block_description. - * - * @param index_sub_block_description A pointer to an IndexSubBlockDescription proto object. - * @param invalid_index_type An enum describing the validity of index. - * @param invalid_property_node A pointer to an invalid ParseKeyValue node, if any. - **/ - IndexProperties(IndexSubBlockDescription *index_sub_block_description, - const InvalidIndexType invalid_index_type = InvalidIndexType::kNone, - const ParseKeyValue *invalid_property_node = nullptr) - : index_sub_block_description_(index_sub_block_description), - invalid_index_type_(invalid_index_type), - invalid_property_node_(invalid_property_node) { - } - - /** - * @brief Virtual Destructor - */ - virtual ~IndexProperties() { - } - - /** - * @brief Returns printable string that specifies reason for invalid index instance. - * - * @return The string describing the reason for invalid index - **/ - virtual std::string getReasonForInvalidIndexDescription() const = 0; - - /** - * @brief Modifies the index description given a set of custom properties - * specified as a key-value list of properties. - * - * @param key_value_list Key Value list of custom properties. - * @return Returns true if the given set of custom properties was valid - * and was applied correctly, otherwise returns false. - **/ - virtual bool addCustomProperties(const PtrList<ParseKeyValue> *key_value_list) = 0; - - /** - * @brief Checks whether this instance describes a valid index or not. - * - * @return True if index description is valid, false otherwise. - **/ - bool isIndexPropertyValid() const { - return invalid_index_type_ == InvalidIndexType::kNone; - } - - /** - * @brief Returns the parse node corresponding for invalid index instance, if any. - * - * @return The parse node. - **/ - const ParseKeyValue* getInvalidPropertyNode() const { - return invalid_property_node_; - } - - /** - * @brief Returns a protobuf object representing the index description. - * - * @return An IndexSubBlockDescription object. - **/ - const IndexSubBlockDescription* getIndexDescription() const { - return index_sub_block_description_.get(); - } - - /** - * @brief A helper function that checks whether the given list of custom properties - * contains duplicate keys or not. - * - * @param key_value_list Key Value list of custom properties. - * @param invalid_node Double pointer to an invalid node that is used to store duplicate node, if any. - * @return Returns true if the given set of custom properties contains duplicate - * keys, otherwise returns false. - **/ - bool hasDuplicateCustomProperty(const PtrList<ParseKeyValue> *key_value_list, const ParseKeyValue **invalid_node) { - // Define an existence map, which checks for duplicate properties in the key_value_list. - std::unordered_map<std::string, bool> is_duplicate_property; - for (const ParseKeyValue &key_value : *key_value_list) { - const std::string key = ToLower(key_value.key()->value()); - if (is_duplicate_property.find(key) != is_duplicate_property.end()) { - *invalid_node = &key_value; - return true; // duplicate found, return true. - } else { - is_duplicate_property[key] = true; - } - } - return false; // no duplicates, return false. - } - - protected: - std::unique_ptr<IndexSubBlockDescription> index_sub_block_description_; - InvalidIndexType invalid_index_type_; - const ParseKeyValue *invalid_property_node_; // referred object owned by ParseIndexProperties class. - - /** - * @brief A setter function that be used to invalidate the index. - * - * @param invalid_index_type An enum corresponding to the reason, which invalidated the index. - * @param invalid_property_node Pointer to the node, which may have caused invalidation. - **/ - void setIndexDescriptionAsInvalid(const InvalidIndexType invalid_index_type, - const ParseKeyValue *invalid_property_node) { - invalid_index_type_ = invalid_index_type; - invalid_property_node_ = invalid_property_node; - index_sub_block_description_.reset(); - } - - private: - DISALLOW_COPY_AND_ASSIGN(IndexProperties); -}; - -/** - * @brief Implementation of index properties for a BitWeaving Index (H or V). - */ -class BitWeavingIndexProperties : public IndexProperties { - public: - static const char *kBitWeavingType; // is of type string. - - /** - * @brief Constructor. - **/ - BitWeavingIndexProperties() - : IndexProperties(new IndexSubBlockDescription()) { - // Default to BITWEAVING_V, custom properties can change this to H. - index_sub_block_description_->set_sub_block_type(IndexSubBlockDescription::BITWEAVING_V); - } - - ~BitWeavingIndexProperties() override { - } - - std::string getReasonForInvalidIndexDescription() const override { - switch (invalid_index_type_) { - case InvalidIndexType::kNone: - return ""; - case InvalidIndexType::kDuplicateKey: // Fall through. - case InvalidIndexType::kInvalidKey: - return "The only valid property for BitWeaving is TYPE."; - case InvalidIndexType::kTypeIsNotString: // Fall through. - case InvalidIndexType::kInvalidValue: - return "The only valid values for TYPE are V or H."; - default: - return "Unknown reason"; - } - } - - bool addCustomProperties(const PtrList<ParseKeyValue> *key_value_list) override { - if (key_value_list->size() == 0u) { - // No properties specified. - return true; - } else if (key_value_list->size() == 1u) { - const ParseKeyValue &key_value = *key_value_list->begin(); - if (key_value.getKeyValueType() != ParseKeyValue::KeyValueType::kStringString) { - setIndexDescriptionAsInvalid(InvalidIndexType::kTypeIsNotString, &key_value); - return false; - } - const std::string key = ToLower(key_value.key()->value()); - const std::string value = ToLower( - static_cast<const ParseKeyStringValue&>(key_value).value()->value()); - if (key.compare(kBitWeavingType) == 0) { - if (value.compare("h") == 0) { - index_sub_block_description_->set_sub_block_type(IndexSubBlockDescription::BITWEAVING_H); - return true; - } else if (value.compare("v") != 0) { - setIndexDescriptionAsInvalid(InvalidIndexType::kInvalidValue, &key_value); - return false; - } else { - // If V was specified, then we do nothing because it's set to V by default. - return true; - } - } else { - // Incorrect key specified. - setIndexDescriptionAsInvalid(InvalidIndexType::kInvalidKey, &key_value); - return false; - } - } else { - // More than one key. This must be an error. - invalid_index_type_ = InvalidIndexType::kDuplicateKey; - return false; - } - } - - private: - DISALLOW_COPY_AND_ASSIGN(BitWeavingIndexProperties); -}; - -/** - * @brief Implementation of index properties for Bloom Filter Index - */ -class BloomFilterIndexProperties : public IndexProperties { - public: - // Index properties associated with this index. - - static const char *kBloomFilterSizeInBytes; // is of type integer - static const char *kBloomFilterNumHashes; // is of type integer - static const char *kBloomFilterProjectElementCount; // is of type integer - - /** - * @brief Constructor. - **/ - BloomFilterIndexProperties() - : IndexProperties(new IndexSubBlockDescription()) { - index_sub_block_description_->set_sub_block_type(IndexSubBlockDescription::BLOOM_FILTER); - - // Initialize the valid_property_map_ for this index with appropriate type for each property. - valid_property_map_[kBloomFilterSizeInBytes] = ParseKeyValue::KeyValueType::kStringInteger; - valid_property_map_[kBloomFilterNumHashes] = ParseKeyValue::KeyValueType::kStringInteger; - valid_property_map_[kBloomFilterProjectElementCount] = ParseKeyValue::KeyValueType::kStringInteger; - } - - ~BloomFilterIndexProperties() override { - } - - std::string getReasonForInvalidIndexDescription() const override { - switch (invalid_index_type_) { - case InvalidIndexType::kNone: - return ""; - case InvalidIndexType::kUnimplemented: - return "Bloom Filter index is not yet implemented"; - case InvalidIndexType::kDuplicateKey: - return "Index property is specified more than once"; - case InvalidIndexType::kInvalidKey: - return "Invalid property for this index"; - case InvalidIndexType::kSizeIsFloat: - return "Size cannot be specified as a float"; - case InvalidIndexType::kSizeIsNegative: - return "Size cannot be negative"; - case InvalidIndexType::kNumHashesIsFloat: - return "Num_hashes cannot be specified as a float"; - case InvalidIndexType::kNumHashesIsNegative: - return "Num_hashes cannot be negative"; - case InvalidIndexType::kProjectedCountIsFloat: - return "Projected_element_count cannot be specified as a float"; - case InvalidIndexType::kProjectedCountIsNegative: - return "Projected_element_count cannot be negative"; - default: - return "Unknown reason"; - } - } - - bool addCustomProperties(const PtrList<ParseKeyValue> *key_value_list) override { - // If the index is unimplemented, skip adding the custom properties. - if (invalid_index_type_ == InvalidIndexType::kUnimplemented) { - return false; - } - - // Verify for duplicates, if any. - if (hasDuplicateCustomProperty(key_value_list, &invalid_property_node_)) { - invalid_index_type_ = InvalidIndexType::kDuplicateKey; - return false; - } - - for (const ParseKeyValue &key_value : *key_value_list) { - const std::string key = ToLower(key_value.key()->value()); - if (key.compare(kBloomFilterSizeInBytes) == 0) { - const ParseKeyIntegerValue *key_integer_value = static_cast<const ParseKeyIntegerValue*>(&key_value); - if (key_integer_value->value()->float_like()) { - setIndexDescriptionAsInvalid(InvalidIndexType::kSizeIsFloat, &key_value); - return false; - } - const std::int64_t bloom_filter_size = key_integer_value->value()->long_value(); - if (bloom_filter_size < 0) { - setIndexDescriptionAsInvalid(InvalidIndexType::kSizeIsNegative, &key_value); - return false; - } - // All good! allow the default bloom filter size to be modified. - index_sub_block_description_->SetExtension(BloomFilterIndexSubBlockDescription::bloom_filter_size, - bloom_filter_size); - } else if (key.compare(kBloomFilterNumHashes) == 0) { - const ParseKeyIntegerValue *key_integer_value = static_cast<const ParseKeyIntegerValue*>(&key_value); - if (key_integer_value->value()->float_like()) { - setIndexDescriptionAsInvalid(InvalidIndexType::kNumHashesIsFloat, &key_value); - return false; - } - const std::int64_t number_of_hashes = key_integer_value->value()->long_value(); - if (number_of_hashes < 0) { - setIndexDescriptionAsInvalid(InvalidIndexType::kNumHashesIsNegative, &key_value); - return false; - } - // All good! allow the default num_hashes to be modified. - index_sub_block_description_->SetExtension(BloomFilterIndexSubBlockDescription::number_of_hashes, - number_of_hashes); - } else if (key.compare(kBloomFilterProjectElementCount) == 0) { - const ParseKeyIntegerValue *key_integer_value = static_cast<const ParseKeyIntegerValue*>(&key_value); - if (key_integer_value->value()->float_like()) { - setIndexDescriptionAsInvalid(InvalidIndexType::kProjectedCountIsFloat, &key_value); - return false; - } - const std::int64_t projected_element_count = key_integer_value->value()->long_value(); - if (projected_element_count < 0) { - setIndexDescriptionAsInvalid(InvalidIndexType::kProjectedCountIsNegative, &key_value); - return false; - } - // All good! allow the default projected_element_count to be modified. - index_sub_block_description_->SetExtension(BloomFilterIndexSubBlockDescription::projected_element_count, - projected_element_count); - } else { - // None of the defined properties matched, this is an invalid property for this index. - setIndexDescriptionAsInvalid(InvalidIndexType::kInvalidKey, &key_value); - return false; - } - } - invalid_index_type_ = InvalidIndexType::kNone; - invalid_property_node_ = nullptr; - return true; - } - - private: - // A map of index property constants and their associated type. - valid_property_map_type valid_property_map_; - - DISALLOW_COPY_AND_ASSIGN(BloomFilterIndexProperties); -}; - -/** - * @brief Implementation of index properties for CSB Tree Index. - */ -class CSBTreeIndexProperties : public IndexProperties { - public: - /** - * @brief Constructor. - **/ - CSBTreeIndexProperties() - : IndexProperties(new IndexSubBlockDescription()) { - index_sub_block_description_->set_sub_block_type(IndexSubBlockDescription::CSB_TREE); - } - - ~CSBTreeIndexProperties() override { - } - - std::string getReasonForInvalidIndexDescription() const override { - switch (invalid_index_type_) { - case InvalidIndexType::kNone: - return ""; - case InvalidIndexType::kUnimplemented: - return "CSB Tree index is not yet implemented"; - case InvalidIndexType::kInvalidKey: - return "CSB Tree index does not define index properties"; - default: - return "Unknown reason"; - } - } - - bool addCustomProperties(const PtrList<ParseKeyValue> *key_value_list) override { - // CSBTreeIndex does not define any additional index property, - // so a call to this function will invalidate the index. - invalid_index_type_ = InvalidIndexType::kInvalidKey; - invalid_property_node_ = nullptr; - index_sub_block_description_.reset(); - return false; - } - - private: - DISALLOW_COPY_AND_ASSIGN(CSBTreeIndexProperties); -}; - -/** - * @brief Implementation of index properties for SMA Index. - */ -class SMAIndexProperties : public IndexProperties { - public: - /** - * @brief Constructor. - */ - SMAIndexProperties() : IndexProperties(new IndexSubBlockDescription()) { - index_sub_block_description_->set_sub_block_type(IndexSubBlockDescription::SMA); - } - - ~SMAIndexProperties() override { - } - - std::string getReasonForInvalidIndexDescription() const override { - switch (invalid_index_type_) { - case InvalidIndexType::kNone: - return ""; - case InvalidIndexType::kInvalidKey: - return "SMA index does not define index properties"; - default: - return "Unknown reason"; - } - } - - bool addCustomProperties(const PtrList<ParseKeyValue> *key_value_list) override { - // SMA does not define any index properties, so calling this function - // will invalidate the index. - invalid_index_type_ = InvalidIndexType::kInvalidKey; - invalid_property_node_ = nullptr; - index_sub_block_description_.reset(); - return false; - } - - private: - DISALLOW_COPY_AND_ASSIGN(SMAIndexProperties); -}; - -/** - * @brief Encapsulates the IndexProperties key-value list. Makes the job - * of resolving IndexProperties easy. - */ -class ParseIndexProperties : public ParseTreeNode { - public: - /** - * @brief Constructor. - * - * @param line_number Beginning line number. - * @param column_number Beginning column number. - * @param properties PtrList to the KeyValues. - */ - ParseIndexProperties(const int line_number, - const int column_number, - PtrList<ParseKeyValue> *key_value_list) - : ParseTreeNode(line_number, column_number), - key_value_list_(key_value_list) { - } - - std::string getName() const override { return "IndexProperties"; } - - const PtrList<ParseKeyValue>* getKeyValueList() const { - return key_value_list_.get(); - } - - protected: - void getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<const ParseTreeNode*> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<const ParseTreeNode*>> *container_child_fields) const override { - for (const ParseKeyValue &index_property : *key_value_list_) { - non_container_child_field_names->push_back("index_property"); - non_container_child_fields->push_back(&index_property); - } - } - - private: - std::unique_ptr<PtrList<ParseKeyValue>> key_value_list_; - - DISALLOW_COPY_AND_ASSIGN(ParseIndexProperties); -}; - -/** @} */ - -} // namespace quickstep - -#endif // QUICKSTEP_PARSER_PARSE_INDEX_PROPERTIES_HPP_
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/parser/ParseJoinedTableReference.cpp ---------------------------------------------------------------------- diff --git a/parser/ParseJoinedTableReference.cpp b/parser/ParseJoinedTableReference.cpp deleted file mode 100644 index b2cbeb2..0000000 --- a/parser/ParseJoinedTableReference.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -#include "parser/ParseJoinedTableReference.hpp" - -#include <string> -#include <type_traits> -#include <vector> - -#include "glog/logging.h" - -namespace quickstep { - -void ParseJoinedTableReference::getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<const ParseTreeNode*> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<const ParseTreeNode*>> *container_child_fields) const { - ParseTableReference::getFieldStringItems(inline_field_names, - inline_field_values, - non_container_child_field_names, - non_container_child_fields, - container_child_field_names, - container_child_fields); - - inline_field_names->push_back("join_type"); - switch (join_type_) { - case JoinType::kInnerJoin: - inline_field_values->push_back("InnerJoin"); - break; - case JoinType::kLeftOuterJoin: - inline_field_values->push_back("LeftOuterJoin"); - break; - case JoinType::kRightOuterJoin: - inline_field_values->push_back("RightOuterJoin"); - break; - case JoinType::kFullOuterJoin: - inline_field_values->push_back("FullOuterJoin"); - break; - default: - LOG(FATAL) << "Invalid JoinType: " - << static_cast<typename std::underlying_type<JoinType>::type>(join_type_); - } - - non_container_child_field_names->push_back("left_table"); - non_container_child_fields->push_back(left_table_.get()); - - non_container_child_field_names->push_back("right_table"); - non_container_child_fields->push_back(right_table_.get()); - - non_container_child_field_names->push_back("join_predicate"); - non_container_child_fields->push_back(join_predicate_.get()); -} - -} // namespace quickstep http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/parser/ParseJoinedTableReference.hpp ---------------------------------------------------------------------- diff --git a/parser/ParseJoinedTableReference.hpp b/parser/ParseJoinedTableReference.hpp deleted file mode 100644 index f1f4aa2..0000000 --- a/parser/ParseJoinedTableReference.hpp +++ /dev/null @@ -1,130 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -#ifndef QUICKSTEP_PARSER_PARSE_JOINED_TABLE_REFERENCE_HPP_ -#define QUICKSTEP_PARSER_PARSE_JOINED_TABLE_REFERENCE_HPP_ - -#include <memory> -#include <string> -#include <vector> - -#include "parser/ParsePredicate.hpp" -#include "parser/ParseTableReference.hpp" -#include "utility/Macros.hpp" - -namespace quickstep { - -class ParseTreeNode; - -/** \addtogroup Parser - * @{ - */ - -/** - * @brief Parsed representation of a joined table. - */ -class ParseJoinedTableReference : public ParseTableReference { - public: - enum class JoinType { - kInnerJoin = 0, - kLeftOuterJoin, - kRightOuterJoin, - kFullOuterJoin - }; - - /** - * @brief Constructor. - * - * @param line_number The line number of the token "JOIN" in the SQL statement. - * @param column_number The column number of the token "JOIN" in the SQL statement. - * @param join_type The join type. - * @param left_table The left-hand side table. - * @param right_table The right-hand side table. - * @param join_predicate The join predicate. - */ - ParseJoinedTableReference(const int line_number, - const int column_number, - const JoinType join_type, - ParseTableReference *left_table, - ParseTableReference *right_table, - ParsePredicate *join_predicate) - : ParseTableReference(line_number, column_number), - join_type_(join_type), - left_table_(left_table), - right_table_(right_table), - join_predicate_(join_predicate) { - } - - TableReferenceType getTableReferenceType() const override { - return kJoinedTableReference; - } - - std::string getName() const override { return "JoinedTable"; } - - /** - * @return The join type. - */ - JoinType join_type() const { - return join_type_; - } - - /** - * @return The left-side table. - */ - const ParseTableReference* left_table() const { - return left_table_.get(); - } - - /** - * @return The right-side table. - */ - const ParseTableReference* right_table() const { - return right_table_.get(); - } - - /** - * @return The join predicate. - */ - const ParsePredicate* join_predicate() const { - return join_predicate_.get(); - } - - protected: - void getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<const ParseTreeNode*> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<const ParseTreeNode*>> *container_child_fields) const override; - - private: - const JoinType join_type_; - std::unique_ptr<ParseTableReference> left_table_; - std::unique_ptr<ParseTableReference> right_table_; - std::unique_ptr<ParsePredicate> join_predicate_; - - DISALLOW_COPY_AND_ASSIGN(ParseJoinedTableReference); -}; - -/** @} */ - -} // namespace quickstep - -#endif /* QUICKSTEP_PARSER_PARSE_JOINED_TABLE_REFERENCE_HPP_ */ http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/parser/ParseKeyValue.hpp ---------------------------------------------------------------------- diff --git a/parser/ParseKeyValue.hpp b/parser/ParseKeyValue.hpp deleted file mode 100644 index 9d6d511..0000000 --- a/parser/ParseKeyValue.hpp +++ /dev/null @@ -1,257 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -#ifndef QUICKSTEP_PARSER_PARSE_KEY_VALUE_HPP_ -#define QUICKSTEP_PARSER_PARSE_KEY_VALUE_HPP_ - -#include <memory> -#include <string> -#include <vector> - -#include "parser/ParseLiteralValue.hpp" -#include "parser/ParseString.hpp" -#include "parser/ParseTreeNode.hpp" -#include "utility/Macros.hpp" -#include "utility/PtrList.hpp" - -namespace quickstep { - -/** - * @brief Base class for the Parse Key Values. - */ -class ParseKeyValue : public ParseTreeNode { - public: - enum class KeyValueType { - kStringString, - kStringStringList, - kStringInteger - }; - - /** - * @brief Single value constructor. - * - * @param line_number Line number of the first token of this node in the SQL statement. - * @param column_number Column number of the first token of this node in the SQL statement. - * @param value A single literal value. - **/ - ParseKeyValue(const int line_number, - const int column_number, - ParseString *key) - : ParseTreeNode(line_number, column_number), - key_(key) { } - - /** - * @brief Destructor. - **/ - ~ParseKeyValue() override { } - - /** - * @brief Get the subclass type of the parse key value. - */ - virtual KeyValueType getKeyValueType() const = 0; - - /** - * @return Pointer to the key string. - */ - const ParseString* key() const { - return key_.get(); - } - - std::string getName() const override { - return "KeyValue"; - } - - protected: - std::unique_ptr<ParseString> key_; -}; - -/** - * @brief The parsed representation of a key-value pair. - **/ -class ParseKeyStringValue : public ParseKeyValue { - public: - /** - * @brief Single value constructor. - * - * @param line_number Line number of the first token of this node in the SQL statement. - * @param column_number Column number of the first token of this node in the SQL statement. - * @param key A parse string representing the key. - * @param value A parse string representing the key. - **/ - ParseKeyStringValue(const int line_number, - const int column_number, - ParseString *key, - ParseString *value) - : ParseKeyValue(line_number, column_number, key), - value_(value) { } - - KeyValueType getKeyValueType() const override { - return ParseKeyValue::KeyValueType::kStringString; - } - - /** - * @return A pointer to the value ParseString. - */ - const ParseString* value() const { - return value_.get(); - } - - std::string getName() const override { - return "KeyStringValue"; - } - - protected: - void getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<const ParseTreeNode*> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<const ParseTreeNode*>> *container_child_fields) const override { - inline_field_names->push_back("key"); - inline_field_values->push_back(key_->value()); - - non_container_child_field_names->push_back("value"); - non_container_child_fields->push_back(value_.get()); - } - - private: - std::unique_ptr<ParseString> value_; - - DISALLOW_COPY_AND_ASSIGN(ParseKeyStringValue); -}; - -/** - * @brief The parsed representation of a key-value pair. Value is a list of values. - **/ -class ParseKeyStringList : public ParseKeyValue { - public: - /** - * @brief Single value constructor. - * - * @param line_number Line number of the first token of this node in the SQL statement. - * @param column_number Column number of the first token of this node in the SQL statement. - * @param key A parse string representing the key. - * @param value A list of string values. - **/ - ParseKeyStringList(const int line_number, - const int column_number, - ParseString *key, - PtrList<ParseString> *value) - : ParseKeyValue(line_number, column_number, key), - value_(value) { } - - KeyValueType getKeyValueType() const override { - return ParseKeyValue::KeyValueType::kStringStringList; - } - - /** - * @return A list of ParseStrings. - */ - const PtrList<ParseString>* value() const { - return value_.get(); - } - - std::string getName() const override { - return "KeyStringList"; - } - - protected: - void getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<const ParseTreeNode*> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<const ParseTreeNode*>> *container_child_fields) const override { - inline_field_names->push_back("key"); - inline_field_values->push_back(key_->value()); - - container_child_field_names->push_back("value_list"); - container_child_fields->emplace_back(); - for (const ParseString &value : *value_) { - container_child_fields->back().push_back(&value); - } - } - - private: - std::unique_ptr<PtrList<ParseString> > value_; - - DISALLOW_COPY_AND_ASSIGN(ParseKeyStringList); -}; - -/** - * @brief The parsed representation of a key-value pair. - **/ -class ParseKeyIntegerValue : public ParseKeyValue { - public: - /** - * @brief Single value constructor. - * - * @param line_number Line number of the first token of this node in the SQL statement. - * @param column_number Column number of the first token of this node in the SQL statement. - * @param key A parse string representing the key. - * @param value A single numeric literal value. - **/ - ParseKeyIntegerValue(const int line_number, - const int column_number, - ParseString *key, - NumericParseLiteralValue *value) - : ParseKeyValue(line_number, column_number, key), - value_(value) { } - - KeyValueType getKeyValueType() const override { - return ParseKeyValue::KeyValueType::kStringInteger; - } - - /** - * @return A pointer to the value ParseString. - */ - const NumericParseLiteralValue* value() const { - return value_.get(); - } - - std::string getName() const override { - return "KeyIntegerValue"; - } - - protected: - void getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<const ParseTreeNode*> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<const ParseTreeNode*>> *container_child_fields) const override { - inline_field_names->push_back("key"); - inline_field_values->push_back(key_->value()); - - non_container_child_field_names->push_back("value"); - non_container_child_fields->push_back(value_.get()); - } - - private: - std::unique_ptr<NumericParseLiteralValue> value_; - - DISALLOW_COPY_AND_ASSIGN(ParseKeyIntegerValue); -}; - -} // namespace quickstep - -#endif // QUICKSTEP_PARSER_PARSE_KEY_VALUE_HPP_ http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/parser/ParseLimit.cpp ---------------------------------------------------------------------- diff --git a/parser/ParseLimit.cpp b/parser/ParseLimit.cpp deleted file mode 100644 index f39c430..0000000 --- a/parser/ParseLimit.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -#include "parser/ParseLimit.hpp" - -#include <string> -#include <vector> - -#include "parser/ParseLiteralValue.hpp" - -namespace quickstep { - -void ParseLimit::getFieldStringItems(std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<const ParseTreeNode*> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<const ParseTreeNode*>> *container_child_fields) const { - non_container_child_field_names->push_back(""); - non_container_child_fields->push_back(limit_expression_.get()); -} - -} // namespace quickstep http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/parser/ParseLimit.hpp ---------------------------------------------------------------------- diff --git a/parser/ParseLimit.hpp b/parser/ParseLimit.hpp deleted file mode 100644 index 2afb049..0000000 --- a/parser/ParseLimit.hpp +++ /dev/null @@ -1,90 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -#ifndef QUICKSTEP_PARSER_PARSE_LIMIT_HPP_ -#define QUICKSTEP_PARSER_PARSE_LIMIT_HPP_ - -#include <memory> -#include <string> -#include <vector> - -#include "parser/ParseLiteralValue.hpp" -#include "parser/ParseTreeNode.hpp" -#include "utility/Macros.hpp" - -namespace quickstep { - -/** \addtogroup Parser - * @{ - */ - -/** - * @brief A parsed representation of LIMIT. - */ -class ParseLimit : public ParseTreeNode { - public: - /** - * @brief Constructor. - * - * @param line_number The line number of "LIMIT" in the SQL statement. - * @param column_number The column number of "LIMIT" in the SQL statement. - * @param limit_expression The LIMIT value expression. - */ - ParseLimit(const int line_number, const int column_number, NumericParseLiteralValue *limit_expression) - : ParseTreeNode(line_number, column_number), - limit_expression_(limit_expression) { - } - - /** - * @brief Destructor. - */ - ~ParseLimit() override {} - - /** - * @brief Gets the LIMIT expression. - * - * @return LIMIT expression - */ - const NumericParseLiteralValue* limit_expression() const { - return limit_expression_.get(); - } - - std::string getName() const override { - return "LIMIT"; - } - - protected: - void getFieldStringItems(std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<const ParseTreeNode*> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<const ParseTreeNode*>> *container_child_fields) const override; - - private: - std::unique_ptr<NumericParseLiteralValue> limit_expression_; - - DISALLOW_COPY_AND_ASSIGN(ParseLimit); -}; - -/** @} */ - -} // namespace quickstep - -#endif /* QUICKSTEP_PARSER_PARSELIMIT_HPP_ */ http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/parser/ParseLiteralValue.cpp ---------------------------------------------------------------------- diff --git a/parser/ParseLiteralValue.cpp b/parser/ParseLiteralValue.cpp deleted file mode 100644 index d4753ab..0000000 --- a/parser/ParseLiteralValue.cpp +++ /dev/null @@ -1,211 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -#ifndef __STDC_FORMAT_MACROS -#define __STDC_FORMAT_MACROS -#endif - -#include "parser/ParseLiteralValue.hpp" - -#include <cinttypes> -#include <cstdint> -#include <cstdio> -#include <limits> -#include <string> -#include <utility> -#include <vector> - -#include "types/DatetimeIntervalType.hpp" -#include "types/DoubleType.hpp" -#include "types/IntType.hpp" -#include "types/LongType.hpp" -#include "types/NullType.hpp" -#include "types/Type.hpp" -#include "types/VarCharType.hpp" -#include "types/YearMonthIntervalType.hpp" -#include "utility/SqlError.hpp" - -#include "glog/logging.h" - -namespace quickstep { - -TypedValue NullParseLiteralValue::concretize( - const Type *type_hint, - const Type **concretized_type) const { - if (type_hint == nullptr) { - *concretized_type = &NullType::InstanceNullable(); - } else { - *concretized_type = &(type_hint->getNullableVersion()); - } - return (*concretized_type)->makeNullValue(); -} - -NumericParseLiteralValue::NumericParseLiteralValue(const int line_number, - const int column_number, - const char *numstring) - : ParseLiteralValue(line_number, column_number), - numeric_string_(numstring) { - float_like_ = (numeric_string_.find('.') != std::string::npos) - || (numeric_string_.find('e') != std::string::npos) - || (numeric_string_.find('E') != std::string::npos); - - if (!float_like_) { - CHECK_EQ(1, std::sscanf(numeric_string_.c_str(), "%" SCNd64, &long_value_)) - << "Failed to parse int64_t from numeric string \"" - << numeric_string_ << "\n"; - } -} - -void NumericParseLiteralValue::prependMinus() { - std::string minused("-"); - minused.append(numeric_string_); - numeric_string_ = std::move(minused); - - if (!float_like_) { - long_value_ = -long_value_; - } -} - -TypedValue NumericParseLiteralValue::concretize( - const Type *type_hint, - const Type **concretized_type) const { - TypedValue parsed_value; - if ((type_hint != nullptr) - && (type_hint->getSuperTypeID() == Type::kNumeric) - && (type_hint->parseValueFromString(numeric_string_, &parsed_value))) { - *concretized_type = &(type_hint->getNonNullableVersion()); - return parsed_value; - } - - if (float_like_) { - *concretized_type = &DoubleType::InstanceNonNullable(); - CHECK((*concretized_type)->parseValueFromString(numeric_string_, &parsed_value)) - << "Failed to parse double from numeric string \"" - << numeric_string_ << "\""; - return parsed_value; - } else { - if ((long_value_ >= std::numeric_limits<int>::min()) - && (long_value_ <= std::numeric_limits<int>::max())) { - *concretized_type = &IntType::InstanceNonNullable(); - return TypedValue(static_cast<int>(long_value_)); - } else { - *concretized_type = &LongType::InstanceNonNullable(); - return TypedValue(long_value_); - } - } -} - -void NumericParseLiteralValue::getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<const ParseTreeNode*> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<const ParseTreeNode*>> *container_child_fields) const { - inline_field_names->push_back("numeric_string"); - inline_field_values->push_back(numeric_string_); - - inline_field_names->push_back("float_like"); - inline_field_values->push_back(float_like_ ? "true" : "false"); -} - -bool StringParseLiteralValue::ParseAmbiguousInterval( - ParseString *value, - StringParseLiteralValue **output) { - *output = new StringParseLiteralValue(value, - nullptr); // Initially no explicit type. - - // Try parsing as DatetimeInterval. - (*output)->explicit_type_ = &DatetimeIntervalType::InstanceNonNullable(); - if ((*output)->tryExplicitTypeParse()) { - return true; - } - - // Try parsing as YearMonthInterval. - (*output)->explicit_type_ = &YearMonthIntervalType::InstanceNonNullable(); - if ((*output)->tryExplicitTypeParse()) { - return true; - } - - delete *output; - *output = nullptr; - return false; -} - -TypedValue StringParseLiteralValue::concretize(const Type *type_hint, - const Type **concretized_type) const { - if (explicit_type_ != nullptr) { - if ((type_hint != nullptr) && (type_hint->isSafelyCoercibleFrom(*explicit_type_))) { - *concretized_type = type_hint; - return type_hint->coerceValue(explicit_parsed_value_, *explicit_type_); - } else { - *concretized_type = explicit_type_; - return explicit_parsed_value_; - } - } else { - TypedValue parsed_value; - if ((type_hint != nullptr) - && (type_hint->parseValueFromString(value_->value(), &parsed_value))) { - *concretized_type = &(type_hint->getNonNullableVersion()); - return parsed_value; - } else { - *concretized_type = &VarCharType::InstanceNonNullable(value_->value().length()); - CHECK((*concretized_type)->parseValueFromString(value_->value(), &parsed_value)); - return parsed_value; - } - } -} - -std::string StringParseLiteralValue::generateName() const { - std::string name; - if (explicit_type_ != nullptr) { - name.append(explicit_type_->getName()); - name.push_back('('); - } - name.push_back('\''); - name.append(value_->value()); - name.push_back('\''); - if (explicit_type_ != nullptr) { - name.push_back(')'); - } - return name; -} - -bool StringParseLiteralValue::tryExplicitTypeParse() { - DCHECK(explicit_type_ != nullptr); - return explicit_type_->parseValueFromString(value_->value(), &explicit_parsed_value_); -} - -void StringParseLiteralValue::getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<const ParseTreeNode*> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<const ParseTreeNode*>> *container_child_fields) const { - inline_field_names->push_back("value"); - inline_field_values->push_back(value_->value()); - - if (explicit_type_ != nullptr) { - inline_field_names->push_back("explicit_type"); - inline_field_values->push_back(explicit_type_->getName()); - } -} - -} // namespace quickstep http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/parser/ParseLiteralValue.hpp ---------------------------------------------------------------------- diff --git a/parser/ParseLiteralValue.hpp b/parser/ParseLiteralValue.hpp deleted file mode 100644 index 105a774..0000000 --- a/parser/ParseLiteralValue.hpp +++ /dev/null @@ -1,354 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -#ifndef QUICKSTEP_PARSER_PARSE_LITERAL_VALUE_HPP_ -#define QUICKSTEP_PARSER_PARSE_LITERAL_VALUE_HPP_ - -#include <cstdint> -#include <memory> -#include <string> -#include <vector> - -#include "parser/ParseString.hpp" -#include "parser/ParseTreeNode.hpp" -#include "types/TypedValue.hpp" -#include "utility/Macros.hpp" - -#include "glog/logging.h" - -namespace quickstep { - -class Type; - -/** \addtogroup Parser - * @{ - */ - -/** - * @brief The parsed representation of a literal data value. - **/ -class ParseLiteralValue : public ParseTreeNode { - public: - /** - * @brief Virtual destructor. - **/ - ~ParseLiteralValue() override { - } - - /** - * @brief Obtain this value as a literal TypedValue in the quickstep type - * system. - * - * @param type_hint A hint of what Type is expected. This may be used to give - * NULL values the correct Type, or to disambiguate between types that - * have similar human-readable text formats. type_hint may be NULL, in - * which case the most sensible guess for the value's Type is used - * (for a NULL literal, the special type NullType is used). - * @param concretized_type After the call, *concretized_type will point to - * the actual Type that the returned TypedValue belongs to. - * @return The concrete version of this literal value. - **/ - virtual TypedValue concretize(const Type *type_hint, - const Type **concretized_type) const = 0; - - /** - * @brief Obtain an exact, deep copy of this ParseLiteralValue. - * - * @return A copy of this ParseLiteralValue. - **/ - virtual ParseLiteralValue* clone() const = 0; - - /** - * @brief Get a human-readable representation of this value. - * - * @return The human-readable form of this value. - **/ - virtual std::string generateName() const = 0; - - protected: - /** - * @brief Constructor. - * - * @param line_number Line number of the first token of this node in the SQL statement. - * @param column_number Column number of the first token of this node in the SQL statement. - **/ - ParseLiteralValue(const int line_number, const int column_number) - : ParseTreeNode(line_number, column_number) { - } - - private: - DISALLOW_COPY_AND_ASSIGN(ParseLiteralValue); -}; - -/** - * @brief The parsed representation of a NULL literal. - **/ -class NullParseLiteralValue: public ParseLiteralValue { - public: - /** - * @brief Constructor. - * - * @param line_number Line number of the first token of this node in the SQL statement. - * @param column_number Column number of the first token of this node in the SQL statement. - **/ - NullParseLiteralValue(const int line_number, const int column_number) - : ParseLiteralValue(line_number, column_number) { - } - - std::string getName() const override { - return "NullLiteral"; - } - - TypedValue concretize(const Type *type_hint, - const Type **concretized_type) const override; - - ParseLiteralValue* clone() const override { - return new NullParseLiteralValue(line_number(), column_number()); - } - - std::string generateName() const override { - return "NULL"; - } - - protected: - void getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<const ParseTreeNode*> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<const ParseTreeNode*>> *container_child_fields) const override { - } - - private: - DISALLOW_COPY_AND_ASSIGN(NullParseLiteralValue); -}; - -/** - * @brief The parsed representation of an unquoted numeric literal. - **/ -class NumericParseLiteralValue : public ParseLiteralValue { - public: - /** - * @brief Constructor. - * - * @param line_number Line number of the first token of this node in the SQL statement. - * @param column_number Column number of the first token of this node in the SQL statement. - * @param numstring The C-string form of the numeric value. - **/ - NumericParseLiteralValue(const int line_number, - const int column_number, - const char *numstring); - - /** - * @brief Destructor. - **/ - ~NumericParseLiteralValue() override { - } - - std::string getName() const override { - return "NumericLiteral"; - } - - /** - * @brief Prepend a minus sign to this numeric value, negating it. - * @note This exists to work around a quirk in our Bison SQL grammar, since - * a minus sign can be the leading character in a negative number OR - * can represent the unary negation operation applied to a numeric - * value. Our solution is to have the Lexer scan all numeric literals - * as unsigned values, while the parser has a rule that calls this - * method when a minus-sign token occurs in front of a numeric literal. - **/ - void prependMinus(); - - /** - * @brief Determine whether this numeric value looks like a floating-point - * value. - * - * @return True if the value is "float-like", false otherwise. - **/ - bool float_like() const { - return float_like_; - } - - /** - * @brief Get this numeric value as a long. - * - * @return This numeric value as a long. - **/ - std::int64_t long_value() const { - DCHECK(!float_like_) - << "Attempted to read integer value from float-like " - << "NumericParseLiteralValue"; - return long_value_; - } - - /** - * @note This implementation of concretize() always tries to honor the given - * type_hint first. If resolution with the supplied type_hint fails, or - * if no type_hint is given, then the following rules apply: - * 1. If the literal contains a decimal point or exponent, resolve as - * DoubleType (unless FloatType is hinted, we always use - * DoubleType for more precision). - * 2. Otherwise, if the literal is in-range for a 32-bit signed - * integer, resolve as IntType. - * 3. Otherwise, resolve as LongType. - **/ - TypedValue concretize(const Type *type_hint, - const Type **concretized_type) const override; - - ParseLiteralValue* clone() const override { - return new NumericParseLiteralValue(line_number(), - column_number(), - numeric_string_.c_str()); - } - - std::string generateName() const override { - return numeric_string_; - } - - protected: - void getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<const ParseTreeNode*> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<const ParseTreeNode*>> *container_child_fields) const override; - - private: - std::int64_t long_value_; - bool float_like_; - - std::string numeric_string_; - - DISALLOW_COPY_AND_ASSIGN(NumericParseLiteralValue); -}; - -/** - * @brief The parsed representation of a quoted string value. This includes - * explicitly typed literals of the form "TYPE 'literal value'". - **/ -class StringParseLiteralValue : public ParseLiteralValue { - public: - /** - * @brief Constructor. - * - * @param value The string. - * @param explicit_type If non-NULL, indicates an explicit Type that appeared - * immediately before a quoted string in the SQL syntax. If NULL, then - * value appeared by itself as a quoted string without an explicit - * Type. - **/ - explicit StringParseLiteralValue(ParseString *value, - const Type *explicit_type) - : ParseLiteralValue(value->line_number(), value->column_number()), - value_(value), - explicit_type_(explicit_type) { - } - - ~StringParseLiteralValue() override { - } - - /** - * @brief Attempt to parse an interval literal that was specified - * in the form "INTERVAL 'value string'" in SQL syntax. - * @note There are two distinct INTERVAL Types in Quickstep: - * DatetimeInterval ("DATETIME INTERVAL" in SQL) and YearMonthInterval - * ("YEARMONTH INTERVAL" in SQL). The INTERVAL keyword by itself is - * ambiguous and does not name a Type, however the text formats for - * literals of the two different interval Types are distinct and - * non-overlapping, so if a valid interval literal string follows the - * INTERVAL keyword, the Type can be determined unambiguously. This - * method does just that, allowing the SQL parser to be more forgiving - * when interval literals don't specify the flavor of interval - * up-front. - * - * @param value A string literal that followed an INTERVAL keyword in SQL - * syntax. On successful parse, this becomes owned by the parsed - * StringParseLiteralValue. On failure, it is deleted. - * @param output On successful parse, *output is overwritten to point to a - * new heap-allocated StringParseLiteralValue representing the parsed - * interval literal. - * @return true if value was successfully parsed as either of the interval - * types, false otherwise. - **/ - static bool ParseAmbiguousInterval(ParseString *value, - StringParseLiteralValue **output); - - /** - * @note The rules for what type this literal is resolved as depend on - * whether an explicit_type_ from the SQL context exists, and whether - * a type_hint is provided. Specifically, they are: - * 1. If there is an explicit_type_: - * a. If there is a type_hint and it is safely coercible from - * explicit_type_, do the coercion and resolve as type_hint. - * b. Otherwise resolve as explicit_type_. - * 2. If there is no explicit_type_: - * a. If there is a type_hint and it can successfully parse the - * string value, resolve as the hinted type. - * b. Otherwise, resolve as a non-nullable VarCharType that is - * exactly long enough for this string literal. - **/ - TypedValue concretize(const Type *type_hint, - const Type **concretized_type) const override; - - std::string getName() const override { - return "StringLiteral"; - } - - ParseLiteralValue* clone() const override { - return new StringParseLiteralValue(value_->clone(), explicit_type_); - } - - std::string generateName() const override; - - /** - * @brief Attempt to parse this string literal as an instance of the - * explicit Type provided to the constructor. This should ALWAYS be - * called by the parser immediately after creating a - * StringParseLiteralValue with an explicit Type. - * - * @return true if parse was successful, false if the string was not in a - * valid format for the specified explicit Type. - **/ - bool tryExplicitTypeParse(); - - protected: - void getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<const ParseTreeNode*> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<const ParseTreeNode*>> *container_child_fields) const override; - - private: - std::unique_ptr<ParseString> value_; - const Type *explicit_type_; - TypedValue explicit_parsed_value_; - - DISALLOW_COPY_AND_ASSIGN(StringParseLiteralValue); -}; - -/** @} */ - -} // namespace quickstep - -#endif // QUICKSTEP_PARSER_PARSE_LITERAL_VALUE_HPP_ http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/parser/ParseOrderBy.cpp ---------------------------------------------------------------------- diff --git a/parser/ParseOrderBy.cpp b/parser/ParseOrderBy.cpp deleted file mode 100644 index da46a1f..0000000 --- a/parser/ParseOrderBy.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -#include "parser/ParseOrderBy.hpp" - -#include <string> -#include <vector> - -#include "parser/ParseExpression.hpp" - -namespace quickstep { - -void ParseOrderByItem::getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<const ParseTreeNode*> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<const ParseTreeNode*>> *container_child_fields) const { - inline_field_names->push_back("is_asc"); - inline_field_values->push_back(is_ascending_ ? "true" : "false"); - inline_field_names->push_back("nulls_first"); - inline_field_values->push_back(nulls_first_ ? "true" : "false"); - - non_container_child_field_names->push_back(""); - non_container_child_fields->push_back(ordering_expression_.get()); -} - -void ParseOrderBy::getFieldStringItems(std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<const ParseTreeNode*> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<const ParseTreeNode*>> *container_child_fields) const { - for (const ParseOrderByItem &order_by_item : *order_by_items_) { - non_container_child_field_names->push_back(""); - non_container_child_fields->push_back(&order_by_item); - } -} - -} // namespace quickstep http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/parser/ParseOrderBy.hpp ---------------------------------------------------------------------- diff --git a/parser/ParseOrderBy.hpp b/parser/ParseOrderBy.hpp deleted file mode 100644 index 88e9679..0000000 --- a/parser/ParseOrderBy.hpp +++ /dev/null @@ -1,167 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -#ifndef QUICKSTEP_PARSER_PARSE_ORDERBY_HPP_ -#define QUICKSTEP_PARSER_PARSE_ORDERBY_HPP_ - -#include <memory> -#include <string> -#include <vector> - -#include "parser/ParseExpression.hpp" -#include "parser/ParseTreeNode.hpp" -#include "utility/Macros.hpp" -#include "utility/PtrList.hpp" - -namespace quickstep { - -/** \addtogroup Parser - * @{ - */ - -/** - * @brief The parsed representation of an ORDER BY item consisting of - * an ordering expression and its ordering direction. - */ -class ParseOrderByItem : public ParseTreeNode { - public: - /** - * @brief Constructor. - * - * @param line_number The line number of the first token of this ORDER BY item - * in the SQL statement. - * @param column_number The column number of the first token of this ORDER BY - * item in the SQL statement. - * @param ordering_expression The ordering expression. - * @param is_ascending The optional ordering direction. The default value is - * true. - * @param nulls_first True if nulls are sorted before non-nulls. - * The default value is true when is_ascending is false, - * false otherwise. - */ - ParseOrderByItem(const int line_number, - const int column_number, - ParseExpression *ordering_expression, - const bool *is_ascending, - const bool *nulls_first) - : ParseTreeNode(line_number, column_number), - ordering_expression_(ordering_expression), - is_ascending_(is_ascending == nullptr ? true : *is_ascending), - nulls_first_(nulls_first == nullptr ? !is_ascending_ : *nulls_first) { - } - - /** - * @brief Destructor. - */ - ~ParseOrderByItem() override {} - - std::string getName() const override { - return "OrderByItem"; - } - - /** - * @return Ordering expression. - */ - const ParseExpression* ordering_expression() const { - return ordering_expression_.get(); - } - - /** - * @return True if the ordering direction is ascending. - */ - bool is_ascending() const { - return is_ascending_; - } - - /** - * @return True if nulls are sorted before other values. - */ - bool nulls_first() const { - return nulls_first_; - } - - protected: - void getFieldStringItems(std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<const ParseTreeNode*> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<const ParseTreeNode*>> *container_child_fields) const override; - - private: - std::unique_ptr<ParseExpression> ordering_expression_; - bool is_ascending_; - bool nulls_first_; - - DISALLOW_COPY_AND_ASSIGN(ParseOrderByItem); -}; - -/** - * @brief The parsed representation of ORDER BY. - */ -class ParseOrderBy : public ParseTreeNode { - public: - /** - * @brief Constructor. - * - * @param line_number The line number of "ORDER" in the SQL statement. - * @param column_number The column number of "ORDER" in the SQL statement. - * @param order_by_items The ORDER BY expression and the ordering direction. - */ - ParseOrderBy(const int line_number, const int column_number, PtrList<ParseOrderByItem> *order_by_items) - : ParseTreeNode(line_number, column_number), order_by_items_(order_by_items) { - } - - /** - * @brief Destructor. - */ - ~ParseOrderBy() override {} - - /** - * @brief Gets the ORDER BY expressions. - * - * @return ORDER BY expressions. - */ - const PtrList<ParseOrderByItem>* order_by_items() const { - return order_by_items_.get(); - } - - std::string getName() const override { - return "OrderBy"; - } - - protected: - void getFieldStringItems(std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<const ParseTreeNode*> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<const ParseTreeNode*>> *container_child_fields) const override; - - private: - std::unique_ptr<PtrList<ParseOrderByItem>> order_by_items_; - - DISALLOW_COPY_AND_ASSIGN(ParseOrderBy); -}; - -/** @} */ - -} // namespace quickstep - -#endif /* QUICKSTEP_PARSER_PARSEORDERBY_HPP_ */ http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/parser/ParsePartitionClause.hpp ---------------------------------------------------------------------- diff --git a/parser/ParsePartitionClause.hpp b/parser/ParsePartitionClause.hpp deleted file mode 100644 index d2912e7..0000000 --- a/parser/ParsePartitionClause.hpp +++ /dev/null @@ -1,134 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -#ifndef QUICKSTEP_PARSER_PARSE_PARTITION_CLAUSE_HPP_ -#define QUICKSTEP_PARSER_PARSE_PARTITION_CLAUSE_HPP_ - -#include <memory> -#include <string> -#include <vector> - -#include "parser/ParseLiteralValue.hpp" -#include "parser/ParseString.hpp" -#include "parser/ParseTreeNode.hpp" -#include "utility/Macros.hpp" -#include "utility/PtrList.hpp" - -namespace quickstep { - -/** \addtogroup Parser - * @{ - */ - -/** - * @brief A parsed representation of partition clause. - */ -class ParsePartitionClause : public ParseTreeNode { - public: - /** - * @brief Constructor. - * - * @param line_number The line number of "PARTITION CLAUSE" in the SQL statement. - * @param column_number The column number of "PARTITION CLAUSE" in the SQL statement. - * @param partition_type The type of partitioning to be made - Hash or Range - * @param attribute_name_list A list of attributes of the relation based on which the partitioning has to be done. - * @param num_partitions The number of partitions to be created. - */ - ParsePartitionClause(const int line_number, - const int column_number, - ParseString *partition_type, - PtrList<ParseString> *attribute_name_list, - NumericParseLiteralValue *num_partitions) - : ParseTreeNode(line_number, column_number), - partition_type_(partition_type), - attribute_name_list_(attribute_name_list), - num_partitions_(num_partitions) { - } - - /** - * @brief Destructor. - */ - ~ParsePartitionClause() override {} - - std::string getName() const override { - return "PartitionClause"; - } - - /** - * @brief Get the type of the partitioning to be created. - * - * @return The type of partitioning. - **/ - const ParseString* partition_type() const { - return partition_type_.get(); - } - - /** - * @brief Get the list of attributes on which partitioning is supposed to be defined. - * - * @return The list of attributes on which partitioning is to be based on. - **/ - const PtrList<ParseString>& attribute_name_list() const { - return *attribute_name_list_; - } - - /** - * @brief Get the number of partitions. - * - * @return The number of partitions. - */ - const NumericParseLiteralValue* num_partitions() const { - return num_partitions_.get(); - } - - protected: - void getFieldStringItems(std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<const ParseTreeNode*> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<const ParseTreeNode*>> *container_child_fields) const override { - inline_field_names->push_back("partition_type"); - inline_field_values->push_back(partition_type_->value()); - - if (attribute_name_list_.get() != nullptr) { - container_child_field_names->push_back("attribute_name_list"); - container_child_fields->emplace_back(); - for (const ParseString& attribute_name : *attribute_name_list_) { - container_child_fields->back().push_back(&attribute_name); - } - } - - non_container_child_field_names->push_back("Number of Partitions"); - non_container_child_fields->push_back(num_partitions_.get()); - } - - private: - std::unique_ptr<ParseString> partition_type_; - std::unique_ptr<PtrList<ParseString>> attribute_name_list_; - std::unique_ptr<NumericParseLiteralValue> num_partitions_; - - DISALLOW_COPY_AND_ASSIGN(ParsePartitionClause); -}; - -/** @} */ - -} // namespace quickstep - -#endif // QUICKSTEP_PARSER_PARSE_PARTITION_CLAUSE_HPP_ http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/parser/ParsePredicate.cpp ---------------------------------------------------------------------- diff --git a/parser/ParsePredicate.cpp b/parser/ParsePredicate.cpp deleted file mode 100644 index 9747b08..0000000 --- a/parser/ParsePredicate.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -#include "parser/ParsePredicate.hpp" - -#include <string> -#include <vector> - -#include "parser/ParseExpression.hpp" -#include "types/operations/comparisons/Comparison.hpp" - -namespace quickstep { - -std::string ParsePredicateComparison::getName() const { - return op_.getName(); -} - -void ParsePredicateComparison::getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<const ParseTreeNode*> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<const ParseTreeNode*>> *container_child_fields) const { - non_container_child_field_names->push_back("left_operand"); - non_container_child_field_names->push_back("right_operand"); - non_container_child_fields->push_back(left_operand_.get()); - non_container_child_fields->push_back(right_operand_.get()); -} - -void ParsePredicateNegation::getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<const ParseTreeNode*> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<const ParseTreeNode*>> *container_child_fields) const { - non_container_child_field_names->push_back(""); - non_container_child_fields->push_back(operand_.get()); -} - -void ParsePredicateBetween::getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<const ParseTreeNode*> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<const ParseTreeNode*>> *container_child_fields) const { - non_container_child_field_names->push_back("check_operand"); - non_container_child_fields->push_back(check_operand_.get()); - - non_container_child_field_names->push_back("lower_bound_operand"); - non_container_child_fields->push_back(lower_bound_operand_.get()); - - non_container_child_field_names->push_back("upper_bound_operand"); - non_container_child_fields->push_back(upper_bound_operand_.get()); -} - -void ParsePredicateWithList::getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<const ParseTreeNode*> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<const ParseTreeNode*>> *container_child_fields) const { - container_child_field_names->push_back(""); - container_child_fields->emplace_back(); - for (const ParsePredicate &operand : operands_) { - container_child_fields->back().push_back(&operand); - } -} - -void ParsePredicateInValueList::getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<const ParseTreeNode*> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<const ParseTreeNode*>> *container_child_fields) const { - non_container_child_field_names->push_back("test_expression"); - non_container_child_fields->push_back(test_expression_.get()); - - container_child_field_names->push_back("value_list"); - container_child_fields->emplace_back(); - for (const ParseExpression &value : *value_list_) { - container_child_fields->back().emplace_back(&value); - } -} - -} // namespace quickstep