diff --git a/velox/type/Type.h b/velox/type/Type.h index 40e00ecd2511..878ca2512851 100644 --- a/velox/type/Type.h +++ b/velox/type/Type.h @@ -1014,7 +1014,8 @@ class RowType : public TypeBase { std::optional getChildIdxIfExists(const std::string& name) const; const std::string& nameOf(uint32_t idx) const { - return names_.at(idx); + VELOX_CHECK_LT(idx, names_.size()); + return names_[idx]; } bool equivalent(const Type& other) const override; diff --git a/velox/type/tests/TypeTest.cpp b/velox/type/tests/TypeTest.cpp index 1bf8d6d384e5..a3ab45a962cd 100644 --- a/velox/type/tests/TypeTest.cpp +++ b/velox/type/tests/TypeTest.cpp @@ -413,7 +413,7 @@ TEST(TypeTest, row) { EXPECT_STREQ(row0->findChild("a")->kindName(), "INTEGER"); EXPECT_EQ(row0->nameOf(0), "a"); EXPECT_EQ(row0->nameOf(1), "b"); - EXPECT_THROW(row0->nameOf(4), std::out_of_range); + EXPECT_THROW(row0->nameOf(4), VeloxRuntimeError); EXPECT_THROW(row0->findChild("not_exist"), VeloxUserError); // todo: expected case behavior?: VELOX_ASSERT_THROW(