Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rui-mo committed Sep 15, 2023
1 parent 4b3a800 commit d342884
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 7 additions & 3 deletions velox/type/Subfield.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ enum SubfieldKind {
kLongSubscript
};

// Contains field name separators to use in Tokenizer.
// Contains field name separators to be used in Tokenizer.
struct Separators {
static const std::shared_ptr<Separators>& get() {
static const std::shared_ptr<Separators> instance{new Separators()};
return instance;
}

bool isSeparator(char c) const {
return (
c == closeBracket || c == dot || c == openBracket || c == quote ||
Expand Down Expand Up @@ -213,8 +218,7 @@ class Subfield {
// Separators: the customized separators to tokenize field name.
explicit Subfield(
const std::string& path,
const std::shared_ptr<Separators>& separators =
std::make_shared<Separators>());
const std::shared_ptr<Separators>& separators = Separators::get());

explicit Subfield(std::vector<std::unique_ptr<PathElement>>&& path);

Expand Down
6 changes: 2 additions & 4 deletions velox/type/tests/SubfieldTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ using namespace facebook::velox::common;

std::vector<std::unique_ptr<Subfield::PathElement>> tokenize(
const std::string& path,
const std::shared_ptr<Separators>& separators =
std::make_shared<Separators>()) {
const std::shared_ptr<Separators>& separators = Separators::get()) {
std::vector<std::unique_ptr<Subfield::PathElement>> elements;
Tokenizer tokenizer(path, separators);
while (tokenizer.hasNext()) {
Expand Down Expand Up @@ -51,8 +50,7 @@ TEST(SubfieldTest, invalidPaths) {

void testColumnName(
const std::string& name,
const std::shared_ptr<Separators>& separators =
std::make_shared<Separators>()) {
const std::shared_ptr<Separators>& separators = Separators::get()) {
auto elements = tokenize(name, separators);
EXPECT_EQ(elements.size(), 1);
EXPECT_EQ(*elements[0].get(), Subfield::NestedField(name));
Expand Down

0 comments on commit d342884

Please sign in to comment.