Commit 64819fef authored by Paul Asmuth's avatar Paul Asmuth
Browse files

QueryTest#TestTypeError

parent 4006498f
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -119,10 +119,10 @@ TEST_CASE(CSVInputStreamTest, TestGetColumnIndexWithoutHeaders, [] () {
          "test/fixtures/gbp_per_country_simple_noheaders.csv"),
      false);

  EXPECT_EQ(table_ref.getColumnIndex("col1"), 1);
  EXPECT_EQ(table_ref.getColumnIndex("col2"), 2);
  EXPECT_EQ(table_ref.getColumnIndex("col3"), 3);
  EXPECT_EQ(table_ref.getColumnIndex("col99"), 99);
  EXPECT_EQ(table_ref.getColumnIndex("col1"), 0);
  EXPECT_EQ(table_ref.getColumnIndex("col2"), 1);
  EXPECT_EQ(table_ref.getColumnIndex("col3"), 2);
  EXPECT_EQ(table_ref.getColumnIndex("col99"), 98);
});

// CSVTableRefTest
+8 −2
Original line number Diff line number Diff line
@@ -42,12 +42,14 @@ CSVInputStream::CSVInputStream(
    row_seperator_(row_seperator),
    quote_char_(quote_char) {}

// FIXPAUL quotechar escaping...
bool CSVInputStream::readNextRow(std::vector<std::string>* target) {
  bool eof = false;

  for (;;) {
    std::string column;
    char byte;
    bool quoted = false;

    for (;;) {
      if (!input_->readNextByte(&byte)) {
@@ -55,14 +57,18 @@ bool CSVInputStream::readNextRow(std::vector<std::string>* target) {
        break;
      }

      if (byte == column_seperator_) {
      if (!quoted && byte == column_seperator_) {
        break;
      }

      if (byte == row_seperator_) {
      if (!quoted && byte == row_seperator_) {
        break;
      }

      if (byte == quote_char_) {
        quoted = !quoted;
      }

      column += byte;
    }

+5 −1
Original line number Diff line number Diff line
@@ -45,7 +45,9 @@ int CSVTableRef::getColumnIndex(const std::string& name) {
      return -1;
    }

    return index;
    if (index > 0) {
      return index - 1;
    }
  }

  return -1;
@@ -70,6 +72,8 @@ bool CSVTableRef::readNextRow(std::vector<SValue>* target) {

  if (!csv_->readNextRow(&row) || row.size() == 0) {
    return false;
  } else {
    row_index_++;
  }

  if (row.size() < min_cols_) {
+22 −1
Original line number Diff line number Diff line
@@ -877,7 +877,7 @@ TEST_CASE(QueryTest, TestNoSuchColumnError, [] () {
    auto csv_table = new csv_backend::CSVTableRef(
        csv_backend::CSVInputStream::openFile(
            "test/fixtures/gbp_per_country_simple.csv"), 
        true);
        false);

    TableRepository repo;
    repo.addTableRef("gbp_per_country",
@@ -893,3 +893,24 @@ TEST_CASE(QueryTest, TestNoSuchColumnError, [] () {
  });
});

TEST_CASE(QueryTest, TestTypeError, [] () {
  EXPECT_EXCEPTION("can't convert String 'United States' to Float", [] () {
    auto csv_table = new csv_backend::CSVTableRef(
        csv_backend::CSVInputStream::openFile(
            "test/fixtures/gbp_per_country.csv"), 
        false);

    TableRepository repo;
    repo.addTableRef("gbp_per_country",
        std::unique_ptr<csv_backend::CSVTableRef>(csv_table));

    auto query = Query(
        "  SELECT"
        "    sum(col4) as global_gbp"
        "  FROM"
        "    gbp_per_country;",
        &repo);
    query.execute();
  });
});