0

Is it possible to write a sensible validation query in Apache Phoenix?

I want something that will send a trivial query to the database, and return a small and predictable result, with no assumptions as to what is already stored in the database. It gets used simply as a way of confirming that the database is alive and responding to requests.

In MySQL, I use SELECT 1, which works admirably. But Phoenix doesn't support this: it insists on having it as SELECT 1 FROM table, and it complains if there's no such table. This is no use to me: it relies on the existence of a particular table on the database.

The best I have come up with so far is

DROP SEQUENCE IF EXISTS completelyimplausiblesequencename

which works, but it's a bit hacky and inelegant, and it does, in principle, alter state.

Anything better?

chiastic-security
  • 20,430
  • 4
  • 39
  • 67

1 Answers1

0

It seems that one can assume the existence of the SYSTEM.CATALOG table, which Phoenix uses to store internal information.

So the way to get a simple validation query that doesn't alter state, even in principle, is

SELECT 1 FROM SYSTEM.CATALOG LIMIT 1

The LIMIT 1 is needed because otherwise you get a 1 returned for every row in the table.

To be precise, this assumes not just the existence of the table, but also that it contains at least one row, but that seems a fairly solid assumption.

chiastic-security
  • 20,430
  • 4
  • 39
  • 67