Skip to content

Commit 21f1e21

Browse files
Yuhtafacebook-github-bot
authored andcommitted
fix: Quote string keys for feature selection (facebookincubator#11779)
Summary: Pull Request resolved: facebookincubator#11779 For Nimble bulk reader we need to pass down the feature selection as JSON string, and when the map key is string, we forgot to quote them so the JSON was invalid. Reviewed By: kevinwilfong Differential Revision: D66885879 fbshipit-source-id: 924c1b7773cbae0306e001ee6e2f2975a1472c88
1 parent 1b5d3db commit 21f1e21

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

velox/common/base/Exceptions.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ std::string errorMessage(fmt::string_view fmt, const Args&... args) {
190190
#define _VELOX_THROW(exception, ...) \
191191
_VELOX_THROW_IMPL(exception, "", ##__VA_ARGS__)
192192

193-
DECLARE_CHECK_FAIL_TEMPLATES(::facebook::velox::VeloxRuntimeError);
193+
DECLARE_CHECK_FAIL_TEMPLATES(::facebook::velox::VeloxRuntimeError)
194194

195195
#define _VELOX_CHECK_IMPL(expr, exprStr, ...) \
196196
_VELOX_CHECK_AND_THROW_IMPL( \
@@ -367,7 +367,7 @@ DECLARE_CHECK_FAIL_TEMPLATES(::facebook::velox::VeloxRuntimeError);
367367
/* isRetriable */ false, \
368368
##__VA_ARGS__)
369369

370-
DECLARE_CHECK_FAIL_TEMPLATES(::facebook::velox::VeloxUserError);
370+
DECLARE_CHECK_FAIL_TEMPLATES(::facebook::velox::VeloxUserError)
371371

372372
// For all below macros, an additional message can be passed using a
373373
// format string and arguments, as with `fmt::format`.

velox/connectors/hive/tests/HiveConnectorTest.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,25 @@ TEST_F(HiveConnectorTest, makeScanSpec_requiredSubfields_mergeMap) {
206206
ASSERT_FALSE(values->childByName("c0c2")->isConstant());
207207
}
208208

209+
TEST_F(
210+
HiveConnectorTest,
211+
makeScanSpec_requiredSubfields_flatMapFeatureSelectionStringKeys) {
212+
auto rowType = ROW({{"c0", MAP(VARCHAR(), BIGINT())}});
213+
auto scanSpec = makeScanSpec(
214+
rowType,
215+
groupSubfields(makeSubfields({"c0[\"foo\"]"})),
216+
{},
217+
nullptr,
218+
{},
219+
{},
220+
{},
221+
pool_.get());
222+
auto* c0 = scanSpec->childByName("c0");
223+
ASSERT_EQ(c0->flatMapFeatureSelection(), std::vector<std::string>({"foo"}));
224+
auto cs = dwio::common::ColumnSelector::fromScanSpec(*scanSpec, rowType);
225+
ASSERT_EQ(cs->findNode("c0")->getNode().expression, "[\"foo\"]");
226+
}
227+
209228
TEST_F(HiveConnectorTest, makeScanSpec_requiredSubfields_allSubscripts) {
210229
auto columnType =
211230
MAP(BIGINT(), ARRAY(ROW({{"c0c0", BIGINT()}, {"c0c1", BIGINT()}})));

velox/dwio/common/ColumnSelector.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,21 @@ std::shared_ptr<ColumnSelector> ColumnSelector::fromScanSpec(
348348
}
349349
std::string name = child->fieldName();
350350
if (!child->flatMapFeatureSelection().empty()) {
351+
const auto& featureIds = child->flatMapFeatureSelection();
352+
const auto& type = rowType->findChild(name);
353+
VELOX_CHECK(type->isMap());
354+
const bool isVarchar = type->asMap().keyType()->isVarchar();
351355
name += "#[";
352-
name += folly::join(',', child->flatMapFeatureSelection());
356+
for (int i = 0; i < featureIds.size(); ++i) {
357+
if (i > 0) {
358+
name += ',';
359+
}
360+
if (isVarchar) {
361+
folly::json::escapeString(featureIds[i], name, {});
362+
} else {
363+
name += featureIds[i];
364+
}
365+
}
353366
name += ']';
354367
}
355368
columnNames.push_back(std::move(name));

0 commit comments

Comments
 (0)