protected void checkPageSource(
      ConnectorPageSource pageSource, List<TestColumn> testColumns, List<Type> types)
      throws IOException {
    try {
      MaterializedResult result = materializeSourceDataStream(SESSION, pageSource, types);

      for (MaterializedRow row : result) {
        for (int i = 0, testColumnsSize = testColumns.size(); i < testColumnsSize; i++) {
          TestColumn testColumn = testColumns.get(i);
          Type type = types.get(i);

          Object actualValue = row.getField(i);
          Object expectedValue = testColumn.getExpectedValue();
          if (actualValue == null) {
            assertEquals(null, expectedValue, String.format("Expected non-null for column %d", i));
          } else if (testColumn.getObjectInspector().getTypeName().equals("float")
              || testColumn.getObjectInspector().getTypeName().equals("double")) {
            assertEquals((double) actualValue, (double) expectedValue, EPSILON);
          } else if (testColumn.getObjectInspector().getTypeName().equals("date")) {
            SqlDate expectedDate = new SqlDate(((Long) expectedValue).intValue());
            assertEquals(actualValue, expectedDate);
          } else if (testColumn.getObjectInspector().getTypeName().equals("timestamp")) {
            SqlTimestamp expectedTimestamp =
                new SqlTimestamp((Long) expectedValue, SESSION.getTimeZoneKey());
            assertEquals(actualValue, expectedTimestamp);
          } else if (testColumn.getObjectInspector().getCategory() == Category.PRIMITIVE) {
            if (expectedValue instanceof Slice) {
              expectedValue = ((Slice) expectedValue).toStringUtf8();
            }

            if (actualValue instanceof Slice) {
              actualValue = ((Slice) actualValue).toStringUtf8();
            }
            if (actualValue instanceof SqlVarbinary) {
              actualValue = new String(((SqlVarbinary) actualValue).getBytes(), UTF_8);
            }
            assertEquals(actualValue, expectedValue, String.format("Wrong value for column %d", i));
          } else {
            BlockBuilder builder = type.createBlockBuilder(new BlockBuilderStatus(), 1);
            type.writeObject(builder, expectedValue);
            expectedValue = type.getObjectValue(SESSION, builder.build(), 0);
            assertEquals(
                actualValue,
                expectedValue,
                String.format("Wrong value for column %s", testColumn.getName()));
          }
        }
      }
    } finally {
      pageSource.close();
    }
  }
  @Test
  public void testViewMetadata() throws Exception {
    @Language("SQL")
    String query = "SELECT 123 x, 'foo' y";
    assertQueryTrue("CREATE VIEW meta_test_view AS " + query);

    // test INFORMATION_SCHEMA.TABLES
    MaterializedResult actual =
        computeActual(
            format(
                "SELECT table_name, table_type FROM information_schema.tables WHERE table_schema = '%s'",
                getSession().getSchema()));

    MaterializedResult expected =
        resultBuilder(getSession(), actual.getTypes())
            .row("customer", "BASE TABLE")
            .row("lineitem", "BASE TABLE")
            .row("meta_test_view", "VIEW")
            .row("nation", "BASE TABLE")
            .row("orders", "BASE TABLE")
            .row("part", "BASE TABLE")
            .row("partsupp", "BASE TABLE")
            .row("region", "BASE TABLE")
            .row("supplier", "BASE TABLE")
            .build();

    assertContains(actual, expected);

    // test SHOW TABLES
    actual = computeActual("SHOW TABLES");

    MaterializedResult.Builder builder = resultBuilder(getSession(), actual.getTypes());
    for (MaterializedRow row : expected.getMaterializedRows()) {
      builder.row(row.getField(0));
    }
    expected = builder.build();

    assertContains(actual, expected);

    // test INFORMATION_SCHEMA.VIEWS
    actual =
        computeActual(
            format(
                "SELECT table_name, view_definition FROM information_schema.views WHERE table_schema = '%s'",
                getSession().getSchema()));

    expected =
        resultBuilder(getSession(), actual.getTypes())
            .row("meta_test_view", formatSql(new SqlParser().createStatement(query)))
            .build();

    assertContains(actual, expected);

    // test SHOW COLUMNS
    actual = computeActual("SHOW COLUMNS FROM meta_test_view");

    expected =
        resultBuilder(getSession(), VARCHAR, VARCHAR, BOOLEAN, BOOLEAN, VARCHAR)
            .row("x", "bigint", true, false, "")
            .row("y", "varchar", true, false, "")
            .build();

    assertEquals(actual, expected);

    assertQueryTrue("DROP VIEW meta_test_view");
  }