@Test
  public void testTableIteration() throws Throwable {
    String scriptText =
            "DROP TABLE IF EXISTS result;\n" +
            "CREATE TABLE result (s string);\n" +
            "DROP TABLE IF EXISTS emp;\n" +
            "CREATE TABLE emp (name string);\n" +
            "INSERT INTO emp VALUES('alice');\n" +
            "INSERT INTO emp VALUES('bob');\n" +
            "TYPE tbl_type IS TABLE OF emp%ROWTYPE INDEX BY BINARY_INTEGER;\n" +
            "DECLARE tbl tbl_type;\n" +
            "SELECT * INTO tbl(1) FROM emp WHERE name = 'bob';\n" +
            "SELECT * INTO tbl(2) FROM emp WHERE name = 'alice';\n" +
            "DECLARE idx INT = tbl.FIRST;\n" +
            "DECLARE s STRING = '';\n" +
            "WHILE idx IS NOT NULL LOOP\n" +
            "   DECLARE r ROW = tbl(idx);\n" +
            "   s = s || r.name || ' ';\n" +
            "   idx = tbl.NEXT(idx);\n" +
            "END LOOP;\n" +
            "INSERT INTO result VALUES(s);\n" +
            "SELECT * FROM result;\n";
    testScriptFile(scriptText, args(), "bob alice ");
  }
Start up a local Hive Server 2 for these tests
itests/hive-unit/src/test/java/org/apache/hive/beeline/TestHplSqlViaBeeLine.java