westonpace commented on a change in pull request #10202:
URL: https://github.com/apache/arrow/pull/10202#discussion_r627655183



##########
File path: cpp/src/arrow/csv/parser_test.cc
##########
@@ -555,6 +555,123 @@ TEST(BlockParser, MismatchingNumColumns) {
   }
 }
 
+TEST(BlockParser, MismatchingNumColumnsSkip) {
+  ParseOptions opts = ParseOptions::Defaults();
+  opts.invalid_row_handler = InvalidRowHandlers::Skip();
+  {
+    BlockParser parser(opts);
+    ASSERT_NO_FATAL_FAILURE(AssertParseOk(parser, "a,b\nc\nd,e\n"));
+    ASSERT_EQ(2, parser.num_rows());
+    ASSERT_NO_FATAL_FAILURE(AssertLastRowEq(parser, {"d", "e"}, {false, 
false}));
+  }
+  {
+    BlockParser parser(opts, 2 /* num_cols */);
+    ASSERT_NO_FATAL_FAILURE(AssertParseOk(parser, "a\nb,c\n"));
+    ASSERT_EQ(1, parser.num_rows());
+    ASSERT_NO_FATAL_FAILURE(AssertLastRowEq(parser, {"b", "c"}, {false, 
false}));
+  }
+  {
+    BlockParser parser(opts, 2 /* num_cols */);
+    ASSERT_NO_FATAL_FAILURE(AssertParseOk(parser, "a,b,c\nd,e\n"));
+    ASSERT_EQ(1, parser.num_rows());
+    ASSERT_NO_FATAL_FAILURE(AssertLastRowEq(parser, {"d", "e"}, {false, 
false}));
+  }
+}
+
+TEST(BlockParser, MismatchingNumColumnsAddNulls) {
+  ParseOptions opts = ParseOptions::Defaults();
+  opts.invalid_row_handler = InvalidRowHandlers::AddNulls("NULL");
+  {
+    BlockParser parser(opts);
+    ASSERT_NO_FATAL_FAILURE(AssertParseOk(parser, "a,b\nc\n"));
+    ASSERT_EQ(2, parser.num_rows());
+    ASSERT_NO_FATAL_FAILURE(AssertLastRowEq(parser, {"c", "NULL"}, {false, 
false}));
+  }
+  {
+    BlockParser parser(opts, 2 /* num_cols */);
+    ASSERT_NO_FATAL_FAILURE(AssertParseOk(parser, "a\n"));
+    ASSERT_EQ(1, parser.num_rows());
+    ASSERT_NO_FATAL_FAILURE(AssertLastRowEq(parser, {"a", "NULL"}, {false, 
false}));
+  }
+  {
+    uint32_t out_size;
+    BlockParser parser(opts, 2 /* num_cols */);
+    Status st = Parse(parser, "a,b,c\nd,e\n", &out_size);
+    ASSERT_RAISES(Invalid, st);
+  }
+}
+
+TEST(BlockParser, MismatchingNumColumnsForce) {
+  ParseOptions opts = ParseOptions::Defaults();
+  opts.invalid_row_handler = InvalidRowHandlers::Force();

Review comment:
       Or you could add a case where the last row is the row being modified.




-- 
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:
us...@infra.apache.org


Reply via email to