17

Is there a maximum number of rows that a JDBC will put into a ResultSet specifically from a Hive query? I am not talking about fetch size or paging, but the total number of rows returned in a ResultSet.

Correct me if I'm wrong, but the fetch size sets the number of rows the jdbc looks at to process with each pass in the database, inserting appropriate responses into the ResultSet. When it has gone through all the records in the table, it returns the ResultSet to the Java code. I am asking if there is a limit to the number of rows returned to the Java code.

If it doesn't have a maximum number of rows, is there anything inherent with the class that may cause some records to be trimmed off?

sparks
  • 736
  • 1
  • 9
  • 29
  • Is the data behind the result set object being updated while the program is running? – Barranka Oct 28 '14 at 22:51
  • 3
    I guess it would be `Integer.MAX_SIZE` – Luiggi Mendoza Oct 28 '14 at 22:51
  • 1
    I would assume that the limitation would be the limit of any collection type used as a base class which I think approaches `Integer.MAX_SIZE` http://stackoverflow.com/a/7632240/16959 or the memory available to store the records (which ever runs out first) – Jason Sperske Oct 28 '14 at 22:51
  • There are also limitations for Java Array lengths http://stackoverflow.com/a/3039805/16959 – Jason Sperske Oct 28 '14 at 22:54
  • You should be able to use the [getMaxRows method of the Statement object](http://docs.oracle.com/javase/6/docs/api/java/sql/Statement.html#getMaxRows%28%29) to see if any limit is set (0 indicates no limit, if there is a limit set excessive rows will be silently dropped), but apart from that I would guess the limit would be bound to memory or some other resource as suggested by the other commenters. – jpw Oct 28 '14 at 22:57

1 Answers1

23

No, it does not work that way. JDBC is just a wrapper around native databases. But either JDBC or database cursors work the same :

  • you send a query (via JDBC) to the database
  • the database analyses the query and initializes the cursor (ResulSet in JDBC)
  • while you fetch data from the ResultSet, the databases software walks in the database to get new rows and populates the ResultSet

So there is no limit to the number of rows that a ResultSet can contains, nor to the number of rows that a java client program can process. The only limit comes if you try to load all the rows in memory to populate a list for example and exhaust the client application memory. But if you process rows and do not keep them in memory, there is no limit (exactly like what happens when you read a file).

Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252