Skip to content

Commit

Permalink
ARROW-17647: [C++] Using better namespace style when using protobuf w…
Browse files Browse the repository at this point in the history
…ith Substrait (apache#14121)

This PR includes minor changes to the namespace usage in Substrait integation.

Authored-by: Vibhatha Abeykoon <vibhatha@gmail.com>
Signed-off-by: Weston Pace <weston.pace@gmail.com>
  • Loading branch information
vibhatha authored and zagto committed Oct 7, 2022
1 parent 15dea3c commit daae1ce
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cpp/src/arrow/engine/substrait/expression_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ Result<std::unique_ptr<substrait::Expression>> ToProto(
if (arguments[0]->has_selection() &&
arguments[0]->selection().has_direct_reference()) {
if (arguments[1]->has_literal() && arguments[1]->literal().literal_type_case() ==
substrait::Expression_Literal::kI32) {
substrait::Expression::Literal::kI32) {
return MakeListElementReference(std::move(arguments[0]),
arguments[1]->literal().i32());
}
Expand Down
23 changes: 12 additions & 11 deletions cpp/src/arrow/engine/substrait/relation_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,23 +165,23 @@ Result<DeclarationInfo> FromProto(const substrait::Rel& rel, const ExtensionSet&
for (const auto& item : read.local_files().items()) {
std::string path;
if (item.path_type_case() ==
substrait::ReadRel_LocalFiles_FileOrFiles::kUriPath) {
substrait::ReadRel::LocalFiles::FileOrFiles::kUriPath) {
path = item.uri_path();
} else if (item.path_type_case() ==
substrait::ReadRel_LocalFiles_FileOrFiles::kUriFile) {
substrait::ReadRel::LocalFiles::FileOrFiles::kUriFile) {
path = item.uri_file();
} else if (item.path_type_case() ==
substrait::ReadRel_LocalFiles_FileOrFiles::kUriFolder) {
substrait::ReadRel::LocalFiles::FileOrFiles::kUriFolder) {
path = item.uri_folder();
} else {
path = item.uri_path_glob();
}

switch (item.file_format_case()) {
case substrait::ReadRel_LocalFiles_FileOrFiles::kParquet:
case substrait::ReadRel::LocalFiles::FileOrFiles::kParquet:
format = std::make_shared<dataset::ParquetFileFormat>();
break;
case substrait::ReadRel_LocalFiles_FileOrFiles::kArrow:
case substrait::ReadRel::LocalFiles::FileOrFiles::kArrow:
format = std::make_shared<dataset::IpcFileFormat>();
break;
default:
Expand Down Expand Up @@ -212,7 +212,7 @@ Result<DeclarationInfo> FromProto(const substrait::Rel& rel, const ExtensionSet&

path = path.substr(7);
switch (item.path_type_case()) {
case substrait::ReadRel_LocalFiles_FileOrFiles::kUriPath: {
case substrait::ReadRel::LocalFiles::FileOrFiles::kUriPath: {
ARROW_ASSIGN_OR_RAISE(auto file, filesystem->GetFileInfo(path));
if (file.type() == fs::FileType::File) {
files.push_back(std::move(file));
Expand All @@ -226,11 +226,11 @@ Result<DeclarationInfo> FromProto(const substrait::Rel& rel, const ExtensionSet&
}
break;
}
case substrait::ReadRel_LocalFiles_FileOrFiles::kUriFile: {
case substrait::ReadRel::LocalFiles::FileOrFiles::kUriFile: {
files.emplace_back(path, fs::FileType::File);
break;
}
case substrait::ReadRel_LocalFiles_FileOrFiles::kUriFolder: {
case substrait::ReadRel::LocalFiles::FileOrFiles::kUriFolder: {
fs::FileSelector selector;
selector.base_dir = path;
selector.recursive = true;
Expand All @@ -240,7 +240,7 @@ Result<DeclarationInfo> FromProto(const substrait::Rel& rel, const ExtensionSet&
std::back_inserter(files));
break;
}
case substrait::ReadRel_LocalFiles_FileOrFiles::kUriPathGlob: {
case substrait::ReadRel::LocalFiles::FileOrFiles::kUriPathGlob: {
ARROW_ASSIGN_OR_RAISE(auto discovered_files,
fs::internal::GlobFiles(filesystem, path));
std::move(discovered_files.begin(), discovered_files.end(),
Expand Down Expand Up @@ -582,15 +582,16 @@ Result<std::unique_ptr<substrait::ReadRel>> ScanRelationConverter(
return Status::Invalid(
"Can only convert scan node with FileSystemDataset to a Substrait plan.");
}

// set schema
ARROW_ASSIGN_OR_RAISE(auto named_struct,
ToProto(*dataset->schema(), ext_set, conversion_options));
read_rel->set_allocated_base_schema(named_struct.release());

// set local files
auto read_rel_lfs = make_unique<substrait::ReadRel_LocalFiles>();
auto read_rel_lfs = make_unique<substrait::ReadRel::LocalFiles>();
for (const auto& file : dataset->files()) {
auto read_rel_lfs_ffs = make_unique<substrait::ReadRel_LocalFiles_FileOrFiles>();
auto read_rel_lfs_ffs = make_unique<substrait::ReadRel::LocalFiles::FileOrFiles>();
read_rel_lfs_ffs->set_uri_path(UriFromAbsolutePath(file));
// set file format
auto format_type_name = dataset->format()->type_name();
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/engine/substrait/type_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ struct DataTypeToProtoImpl {
template <typename T>
Status EncodeUserDefined(const T& t) {
ARROW_ASSIGN_OR_RAISE(auto anchor, ext_set_->EncodeType(t));
auto user_defined = internal::make_unique<::substrait::Type_UserDefined>();
auto user_defined = internal::make_unique<::substrait::Type::UserDefined>();
user_defined->set_type_reference(anchor);
user_defined->set_nullability(nullable_ ? ::substrait::Type::NULLABILITY_NULLABLE
: ::substrait::Type::NULLABILITY_REQUIRED);
Expand Down

0 comments on commit daae1ce

Please sign in to comment.