You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2020/01/13 12:31:43 UTC

[GitHub] [incubator-doris] lingbin opened a new pull request #2747: Add path util

lingbin opened a new pull request #2747: Add path util
URL: https://github.com/apache/incubator-doris/pull/2747
 
 
   Note that the methods in path_util are only related to path processing,
   and do not involve any file and IO operations
   
   The upcoming patch will use these util methods, used to extract operations
   such as concatenation of directory strings from processing logic.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] lingbin commented on a change in pull request #2747: Add path util

Posted by GitBox <gi...@apache.org>.
lingbin commented on a change in pull request #2747: Add path util
URL: https://github.com/apache/incubator-doris/pull/2747#discussion_r366139416
 
 

 ##########
 File path: be/test/util/path_util_test.cpp
 ##########
 @@ -0,0 +1,85 @@
+// 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 "util/path_util.h"
+
+#include <string>
+#include <vector>
+
+#include <gtest/gtest.h>
+
+#include "common/config.h"
+#include "util/logging.h"
+
+
+using std::string;
+using std::vector;
+
+namespace doris {
+
+TEST(TestPathUtil, BaseNameTest) {
+    ASSERT_EQ(".", path_util::base_name(""));
 
 Review comment:
   `ASSERT_EQ()` use the `==` operator to compare, so if it is wrong to use `ASSERT_EQ` on **two C-strings** because it can only test if they are in the same memory location, not if they have the same value.  i.e., only if the two string param both are C-string, `ASSERT_STREQ` should be used. 
   
   on the other hand, If one of the two string param in `ASSERT()` is not C-string, we should use `ASSERT_EQ()`, and here, the second param is an `std::string` type, so use `ASSET_EQ()` is right. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] lingbin commented on a change in pull request #2747: Add path util

Posted by GitBox <gi...@apache.org>.
lingbin commented on a change in pull request #2747: Add path util
URL: https://github.com/apache/incubator-doris/pull/2747#discussion_r366140758
 
 

 ##########
 File path: be/src/util/path_util.cpp
 ##########
 @@ -0,0 +1,88 @@
+// 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 "util/path_util.h"
+
+// Use the POSIX version of dirname(3). See `man 3 dirname`
+#include <libgen.h>
+
+#include <cstring>
+
+#include <common/logging.h>
+#include "gutil/strings/split.h"
+#include "gutil/strings/stringpiece.h"
+#include "gutil/strings/strip.h"
+#include "env/env.h"
+#include "common/status.h"
+
+using std::string;
+using std::vector;
+using strings::SkipEmpty;
+using strings::Split;
+
+namespace doris {
+namespace path_util {
+
+const string kTmpInfix = ".doristmp";
+
+string join_path_segments(const string& a, const string& b) {
+    CHECK(!a.empty()) << "empty first component: " << a;
+    CHECK(!b.empty() && b[0] != '/')
+            << "second path component must be non-empty and relative: "
+            << b;
 
 Review comment:
   I will change it to `DCHECK`.
   
   BTW, for file systems that simulate a hierarchical structure, repeated '/' can be problematic.  For example: in some object-storage-services, it may consider `"/a/b"` and `"/a///b"` as different objects. And during the file operation, no error will be reported, so check here to avoid such errors.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2747: Add path util

Posted by GitBox <gi...@apache.org>.
imay commented on a change in pull request #2747: Add path util
URL: https://github.com/apache/incubator-doris/pull/2747#discussion_r365851958
 
 

 ##########
 File path: be/test/util/path_util_test.cpp
 ##########
 @@ -0,0 +1,85 @@
+// 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 "util/path_util.h"
+
+#include <string>
+#include <vector>
+
+#include <gtest/gtest.h>
+
+#include "common/config.h"
+#include "util/logging.h"
+
+
+using std::string;
+using std::vector;
+
+namespace doris {
+
+TEST(TestPathUtil, BaseNameTest) {
+    ASSERT_EQ(".", path_util::base_name(""));
 
 Review comment:
   should be STREQ?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2747: Add path util

Posted by GitBox <gi...@apache.org>.
imay commented on a change in pull request #2747: Add path util
URL: https://github.com/apache/incubator-doris/pull/2747#discussion_r365859436
 
 

 ##########
 File path: be/src/util/path_util.cpp
 ##########
 @@ -0,0 +1,88 @@
+// 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 "util/path_util.h"
+
+// Use the POSIX version of dirname(3). See `man 3 dirname`
+#include <libgen.h>
+
+#include <cstring>
+
+#include <common/logging.h>
+#include "gutil/strings/split.h"
+#include "gutil/strings/stringpiece.h"
+#include "gutil/strings/strip.h"
+#include "env/env.h"
+#include "common/status.h"
+
+using std::string;
+using std::vector;
+using strings::SkipEmpty;
+using strings::Split;
+
+namespace doris {
+namespace path_util {
+
+const string kTmpInfix = ".doristmp";
+
+string join_path_segments(const string& a, const string& b) {
+    CHECK(!a.empty()) << "empty first component: " << a;
+    CHECK(!b.empty() && b[0] != '/')
+            << "second path component must be non-empty and relative: "
+            << b;
 
 Review comment:
   I don't think it's a good idea to CHECK common function's input arguments

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] lingbin commented on a change in pull request #2747: Add path util

Posted by GitBox <gi...@apache.org>.
lingbin commented on a change in pull request #2747: Add path util
URL: https://github.com/apache/incubator-doris/pull/2747#discussion_r366135286
 
 

 ##########
 File path: be/test/util/path_util_test.cpp
 ##########
 @@ -0,0 +1,85 @@
+// 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 "util/path_util.h"
+
+#include <string>
+#include <vector>
+
+#include <gtest/gtest.h>
+
+#include "common/config.h"
+#include "util/logging.h"
+
+
+using std::string;
+using std::vector;
+
+namespace doris {
+
+TEST(TestPathUtil, BaseNameTest) {
+    ASSERT_EQ(".", path_util::base_name(""));
+    ASSERT_EQ(".", path_util::base_name("."));
+    ASSERT_EQ("..", path_util::base_name(".."));
+    ASSERT_EQ("/", path_util::base_name("/"));
+    ASSERT_EQ("/", path_util::base_name("//"));
+    ASSERT_EQ("a", path_util::base_name("a"));
+    ASSERT_EQ("ab", path_util::base_name("ab"));
+    ASSERT_EQ("ab", path_util::base_name("ab/"));
+    ASSERT_EQ("cd", path_util::base_name("ab/cd"));
+    ASSERT_EQ("ab", path_util::base_name("/ab"));
+    ASSERT_EQ("ab", path_util::base_name("/ab///"));
+    ASSERT_EQ("cd", path_util::base_name("/ab/cd"));
+}
+
+TEST(TestPathUtil, DirNameTest) {
+    ASSERT_EQ(".", path_util::dir_name(""));
+    ASSERT_EQ(".", path_util::dir_name("."));
+    ASSERT_EQ(".", path_util::dir_name(".."));
+    ASSERT_EQ("/", path_util::dir_name("/"));
+    ASSERT_EQ("//", path_util::dir_name("//"));
+    ASSERT_EQ(".", path_util::dir_name("a"));
+    ASSERT_EQ(".", path_util::dir_name("ab"));
+    ASSERT_EQ(".", path_util::dir_name("ab/"));
+    ASSERT_EQ("ab", path_util::dir_name("ab/cd"));
+    ASSERT_EQ("/", path_util::dir_name("/ab"));
+    ASSERT_EQ("/", path_util::dir_name("/ab///"));
+    ASSERT_EQ("/ab", path_util::dir_name("/ab/cd"));
+}
+
+TEST(TestPathUtil, SplitPathTest) {
+    using Vec = vector<string>;
+    ASSERT_EQ(Vec({"/"}), path_util::split_path("/"));
+    ASSERT_EQ(Vec({"/", "a", "b"}), path_util::split_path("/a/b"));
+    ASSERT_EQ(Vec({"/", "a", "b"}), path_util::split_path("/a/b/"));
+    ASSERT_EQ(Vec({"a", "b"}), path_util::split_path("a/b"));
+    ASSERT_EQ(Vec({"."}), path_util::split_path("."));
+    ASSERT_EQ(Vec(), path_util::split_path(""));
+}
+
+} // namespace doris
+
+int main(int argc, char* argv[]) {
+    std::string conffile = std::string(getenv("DORIS_HOME")) + "/conf/be.conf";
+    if (!doris::config::init(conffile.c_str(), false)) {
+        fprintf(stderr, "error read config file. \n");
+        return -1;
+    }
+    doris::init_glog("be-test");
 
 Review comment:
   Done.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] lingbin commented on a change in pull request #2747: Add path util

Posted by GitBox <gi...@apache.org>.
lingbin commented on a change in pull request #2747: Add path util
URL: https://github.com/apache/incubator-doris/pull/2747#discussion_r366139416
 
 

 ##########
 File path: be/test/util/path_util_test.cpp
 ##########
 @@ -0,0 +1,85 @@
+// 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 "util/path_util.h"
+
+#include <string>
+#include <vector>
+
+#include <gtest/gtest.h>
+
+#include "common/config.h"
+#include "util/logging.h"
+
+
+using std::string;
+using std::vector;
+
+namespace doris {
+
+TEST(TestPathUtil, BaseNameTest) {
+    ASSERT_EQ(".", path_util::base_name(""));
 
 Review comment:
   `ASSERT_EQ()` use the `==` operator to compare, so if it is wrong to use `ASSERT_EQ` on **two C-strings** because it can only test if they are in the same memory location, not if they have the same value.  i.e., only if the two string param both are C-string, `ASSERT_STREQ` should be used. 
   
   on the other hand, If one of the two string param in `ASSERT()` is not C-string, we should use `ASSERT_EQ`, and here, the second param is an `std::string` type, so use `ASSET_EQ` is right. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2747: Add path util

Posted by GitBox <gi...@apache.org>.
imay commented on a change in pull request #2747: Add path util
URL: https://github.com/apache/incubator-doris/pull/2747#discussion_r365851588
 
 

 ##########
 File path: be/test/util/path_util_test.cpp
 ##########
 @@ -0,0 +1,85 @@
+// 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 "util/path_util.h"
+
+#include <string>
+#include <vector>
+
+#include <gtest/gtest.h>
+
+#include "common/config.h"
+#include "util/logging.h"
+
+
+using std::string;
+using std::vector;
+
+namespace doris {
+
+TEST(TestPathUtil, BaseNameTest) {
+    ASSERT_EQ(".", path_util::base_name(""));
+    ASSERT_EQ(".", path_util::base_name("."));
+    ASSERT_EQ("..", path_util::base_name(".."));
+    ASSERT_EQ("/", path_util::base_name("/"));
+    ASSERT_EQ("/", path_util::base_name("//"));
+    ASSERT_EQ("a", path_util::base_name("a"));
+    ASSERT_EQ("ab", path_util::base_name("ab"));
+    ASSERT_EQ("ab", path_util::base_name("ab/"));
+    ASSERT_EQ("cd", path_util::base_name("ab/cd"));
+    ASSERT_EQ("ab", path_util::base_name("/ab"));
+    ASSERT_EQ("ab", path_util::base_name("/ab///"));
+    ASSERT_EQ("cd", path_util::base_name("/ab/cd"));
+}
+
+TEST(TestPathUtil, DirNameTest) {
+    ASSERT_EQ(".", path_util::dir_name(""));
+    ASSERT_EQ(".", path_util::dir_name("."));
+    ASSERT_EQ(".", path_util::dir_name(".."));
+    ASSERT_EQ("/", path_util::dir_name("/"));
+    ASSERT_EQ("//", path_util::dir_name("//"));
+    ASSERT_EQ(".", path_util::dir_name("a"));
+    ASSERT_EQ(".", path_util::dir_name("ab"));
+    ASSERT_EQ(".", path_util::dir_name("ab/"));
+    ASSERT_EQ("ab", path_util::dir_name("ab/cd"));
+    ASSERT_EQ("/", path_util::dir_name("/ab"));
+    ASSERT_EQ("/", path_util::dir_name("/ab///"));
+    ASSERT_EQ("/ab", path_util::dir_name("/ab/cd"));
+}
+
+TEST(TestPathUtil, SplitPathTest) {
+    using Vec = vector<string>;
+    ASSERT_EQ(Vec({"/"}), path_util::split_path("/"));
+    ASSERT_EQ(Vec({"/", "a", "b"}), path_util::split_path("/a/b"));
+    ASSERT_EQ(Vec({"/", "a", "b"}), path_util::split_path("/a/b/"));
+    ASSERT_EQ(Vec({"a", "b"}), path_util::split_path("a/b"));
+    ASSERT_EQ(Vec({"."}), path_util::split_path("."));
+    ASSERT_EQ(Vec(), path_util::split_path(""));
+}
+
+} // namespace doris
+
+int main(int argc, char* argv[]) {
+    std::string conffile = std::string(getenv("DORIS_HOME")) + "/conf/be.conf";
+    if (!doris::config::init(conffile.c_str(), false)) {
+        fprintf(stderr, "error read config file. \n");
+        return -1;
+    }
+    doris::init_glog("be-test");
 
 Review comment:
   can you remove these codes to make it run without conf?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] morningman commented on a change in pull request #2747: Add path util

Posted by GitBox <gi...@apache.org>.
morningman commented on a change in pull request #2747: Add path util
URL: https://github.com/apache/incubator-doris/pull/2747#discussion_r367444551
 
 

 ##########
 File path: be/src/util/path_util.cpp
 ##########
 @@ -0,0 +1,88 @@
+// 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 "util/path_util.h"
+
+// Use the POSIX version of dirname(3). See `man 3 dirname`
+#include <libgen.h>
+
+#include <cstring>
+
+#include <common/logging.h>
+#include "gutil/strings/split.h"
+#include "gutil/strings/stringpiece.h"
+#include "gutil/strings/strip.h"
+#include "env/env.h"
+#include "common/status.h"
+
+using std::string;
+using std::vector;
+using strings::SkipEmpty;
+using strings::Split;
+
+namespace doris {
+namespace path_util {
+
+const string kTmpInfix = ".doristmp";
+
+string join_path_segments(const string& a, const string& b) {
+    CHECK(!a.empty()) << "empty first component: " << a;
+    CHECK(!b.empty() && b[0] != '/')
+            << "second path component must be non-empty and relative: "
+            << b;
+    if (a.back() == '/') {
+        return a + b;
+    } else {
+        return a + "/" + b;
+    }
+}
+
+vector<string> join_path_segments_v(const vector<string>& v, const string& s) {
+    vector<string> out;
+    for (const string& path : v) {
+        out.emplace_back(join_path_segments(path, s));
+    }
+    return out;
+}
+
+vector<string> split_path(const string& path) {
 
 Review comment:
   What if i pass "/a//b///c" ? Is it valid?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] lingbin commented on a change in pull request #2747: Add path util

Posted by GitBox <gi...@apache.org>.
lingbin commented on a change in pull request #2747: Add path util
URL: https://github.com/apache/incubator-doris/pull/2747#discussion_r367755838
 
 

 ##########
 File path: be/src/util/path_util.cpp
 ##########
 @@ -0,0 +1,88 @@
+// 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 "util/path_util.h"
+
+// Use the POSIX version of dirname(3). See `man 3 dirname`
+#include <libgen.h>
+
+#include <cstring>
+
+#include <common/logging.h>
+#include "gutil/strings/split.h"
+#include "gutil/strings/stringpiece.h"
+#include "gutil/strings/strip.h"
+#include "env/env.h"
+#include "common/status.h"
+
+using std::string;
+using std::vector;
+using strings::SkipEmpty;
+using strings::Split;
+
+namespace doris {
+namespace path_util {
+
+const string kTmpInfix = ".doristmp";
+
+string join_path_segments(const string& a, const string& b) {
+    CHECK(!a.empty()) << "empty first component: " << a;
+    CHECK(!b.empty() && b[0] != '/')
+            << "second path component must be non-empty and relative: "
+            << b;
+    if (a.back() == '/') {
+        return a + b;
+    } else {
+        return a + "/" + b;
+    }
+}
+
+vector<string> join_path_segments_v(const vector<string>& v, const string& s) {
+    vector<string> out;
+    for (const string& path : v) {
+        out.emplace_back(join_path_segments(path, s));
+    }
+    return out;
+}
+
+vector<string> split_path(const string& path) {
 
 Review comment:
   Yes, it still works, I will add a test case.
   
   But to be clear: this should not happen in theory. Because the paths we configure will be canonicalized when the process starts, that is to say, the redundant contents such as "///" and "./a/../" have already been removed.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay merged pull request #2747: Add path util

Posted by GitBox <gi...@apache.org>.
imay merged pull request #2747: Add path util
URL: https://github.com/apache/incubator-doris/pull/2747
 
 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] lingbin commented on a change in pull request #2747: Add path util

Posted by GitBox <gi...@apache.org>.
lingbin commented on a change in pull request #2747: Add path util
URL: https://github.com/apache/incubator-doris/pull/2747#discussion_r366139416
 
 

 ##########
 File path: be/test/util/path_util_test.cpp
 ##########
 @@ -0,0 +1,85 @@
+// 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 "util/path_util.h"
+
+#include <string>
+#include <vector>
+
+#include <gtest/gtest.h>
+
+#include "common/config.h"
+#include "util/logging.h"
+
+
+using std::string;
+using std::vector;
+
+namespace doris {
+
+TEST(TestPathUtil, BaseNameTest) {
+    ASSERT_EQ(".", path_util::base_name(""));
 
 Review comment:
   `ASSERT_EQ()` use the `==` operator to compare, so it is wrong to use `ASSERT_EQ` on **two C-strings** because it can only test if they are in the same memory location, not if they have the same value.  i.e., only if the two string param both are C-string, `ASSERT_STREQ` should be used. 
   
   on the other hand, If one of the two string param in `ASSERT()` is not C-string, we should use `ASSERT_EQ()`, and here, the second param is an `std::string` type, so use `ASSET_EQ()` is right. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org