|
| 1 | +/* |
| 2 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | + * you may not use this file except in compliance with the License. |
| 4 | + * You may obtain a copy of the License at |
| 5 | + * |
| 6 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | + * |
| 8 | + * Unless required by applicable law or agreed to in writing, software |
| 9 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | + * See the License for the specific language governing permissions and |
| 12 | + * limitations under the License. |
| 13 | + */ |
| 14 | + |
| 15 | +#include <gtest/gtest.h> |
| 16 | + |
| 17 | +#include "presto_cpp/main/common/Configs.h" |
| 18 | +#include "presto_cpp/main/common/tests/MutableConfigs.h" |
| 19 | +#include "presto_cpp/main/types/TypeParser.h" |
| 20 | +#include "velox/common/file/FileSystems.h" |
| 21 | +#include "velox/common/base/tests/GTestUtils.h" |
| 22 | +#include "velox/functions/prestosql/types/BigintEnumRegistration.h" |
| 23 | +#include "velox/functions/prestosql/types/VarcharEnumRegistration.h" |
| 24 | + |
| 25 | + |
| 26 | +using namespace facebook::presto; |
| 27 | +using namespace facebook::velox; |
| 28 | + |
| 29 | +class TypeParserTest : public ::testing::Test { |
| 30 | + void SetUp() override { |
| 31 | + filesystems::registerLocalFileSystem(); |
| 32 | + test::setupMutableSystemConfig(); |
| 33 | + registerBigintEnumType(); |
| 34 | + registerVarcharEnumType(); |
| 35 | + } |
| 36 | +}; |
| 37 | + |
| 38 | +// Test basical functionality of TypeParser. |
| 39 | +// More detailed tests for Presto TypeParser are in velox/functions/prestosql/types/parser/tests/TypeParserTest. |
| 40 | +TEST_F(TypeParserTest, parseEnumTypes) { |
| 41 | + TypeParser typeParser = TypeParser(); |
| 42 | + |
| 43 | + ASSERT_EQ( |
| 44 | + typeParser.parse( |
| 45 | + "test.enum.mood:BigintEnum(test.enum.mood{\"CURIOUS\":2, \"HAPPY\":0})")->toString(), |
| 46 | + "test.enum.mood:BigintEnum({\"CURIOUS\": 2, \"HAPPY\": 0})"); |
| 47 | + ASSERT_EQ( |
| 48 | + typeParser.parse( |
| 49 | + "test.enum.mood:VarcharEnum(test.enum.mood{\"CURIOUS\":\"ONXW2ZKWMFWHKZI=\", \"HAPPY\":\"ONXW2ZJAOZQWY5LF\" , \"SAD\":\"KNHU2RJAKZAUYVKF\"})")->toString(), |
| 50 | + "test.enum.mood:VarcharEnum({\"CURIOUS\": \"someValue\", \"HAPPY\": \"some value\", \"SAD\": \"SOME VALUE\"})"); |
| 51 | + |
| 52 | + // When set to false, TypeParser will throw an unsupported error when it receives an enum type. |
| 53 | + SystemConfig::instance()->setValue(std::string(SystemConfig::kEnumTypesEnabled), "false"); |
| 54 | + |
| 55 | + VELOX_ASSERT_THROW( |
| 56 | + typeParser.parse( |
| 57 | + "test.enum.mood:BigintEnum(test.enum.mood{\"CURIOUS\":2, \"HAPPY\":0})"), |
| 58 | + "Unsupported type: test.enum.mood:BigintEnum(test.enum.mood{\"CURIOUS\":2, \"HAPPY\":0})"); |
| 59 | + VELOX_ASSERT_THROW( |
| 60 | + typeParser.parse( |
| 61 | + "test.enum.mood:VarcharEnum(test.enum.mood{\"CURIOUS\":\"ONXW2ZKWMFWHKZI=\", \"HAPPY\":\"ONXW2ZJAOZQWY5LF\" , \"SAD\":\"KNHU2RJAKZAUYVKF\"})"), |
| 62 | + "Unsupported type: test.enum.mood:VarcharEnum(test.enum.mood{\"CURIOUS\":\"ONXW2ZKWMFWHKZI=\", \"HAPPY\":\"ONXW2ZJAOZQWY5LF\" , \"SAD\":\"KNHU2RJAKZAUYVKF\"})"); |
| 63 | +} |
0 commit comments