IMPALA-1178: fix Impalad crashes during query cancellation

There are several variants of races that can occur if a query is unregistered
or cancelled before it's fully running.  Normally, this will only happen when
the session or connection is closed, because the 16-byte query-id won't yet be
available to a client to cancel/close the specific query until after
ExecuteStatement and friends have returned the query_id.  However, it could
also be triggered via the web interface or if a user were able to "guess" the
query-id before it's returned by ExecuteStatement (e.g. by scraping the web
interface where queries show up "early", though for HS2 could implement secret
to prevent that).

Here's some examples of the race (the first leads to the DCHECK reported in
the jira).

* If session is closed and query unregistered before exec_state->WaitAsync()
  completes, then the async thread would be freed while still executing.
* If the query is cancelled before coord_ is set, then exec_state->Cancel()
  won't be effective.
* If Coordinator::Cancel() is called before executor_ is set, then fragment
  cancel won't be effective.
* Lot's of other points with inconsistent state (but not safe to hold the
  lock) where correctness is hard to reason about.

The session->inflight_queries already tracks which queries to unregister when
a session is closed.  Delay adding queries to this set until after it is safe
to cancel.  This handles the session/connection close case.

Then, add a boolean arguement to UnregisterQuery and CancelInteral that
indicates whether these should return error if the query is not yet in-flight.
When UnregisterQuery() is used to clean up after an error on the query issue
path (when the query is not yet in-filght) will pass false.  Otherwise, the
other paths will pass true, and this in-flight check will guard against the
race from the CancelOperation RPC path.

Also, fix a race in query expiration.  Previously queries could be processed
by ExpireSessions() before last_active_time_ was set (though in practice it'd
be hard to hit this race because timeouts are specified in seconds) and before
it's safe to cancel.

Testing:
- verified this fixes the crashes/hangs using the steps to reproduce given in
  IMPALA-1178.
- Attempted to add a pytest case for this but so far I've had no luck
  reproducing it programmatically.  Will try some more and follow up with a
  separate change when that's successful.

Change-Id: Iec6b977e28fbec2d8bcc2734d1b7c17604e44180
Reviewed-on: http://gerrit.sjc.cloudera.com:8080/4245
Reviewed-by: Daniel Hecht <dhecht@cloudera.com>
Tested-by: jenkins
IMPALA-1297: Results of NOT IN may not be correct if subquery results in
NULL

This commit fixes a bug in the implementation of the null-aware anti
join that resulted in wrong results being returned from NOT IN correlated
subqueries in the presence of nulls.

Change-Id: I6f2eb326ec7e40d80ec8da94ba33946b9ac9b115
Reviewed-on: http://gerrit.sjc.cloudera.com:8080/4506
Reviewed-by: Dimitris Tsirogiannis <dtsirogiannis@cloudera.com>
Tested-by: jenkins
Char Partition Fix

Fixed bug CHAR and VARCHAR partition columns. Also, disables CHAR and VARCHAR for UDAs
and UDFs.

Change-Id: I67ccd746cb4c063f8a7a984df9564fa9122fdf43
Reviewed-on: http://gerrit.sjc.cloudera.com:8080/4493
Reviewed-by: Nong Li <nong@cloudera.com>
Tested-by: jenkins
Analytic fn query test for IMPALA-1280 needs VERIFY_IS_EQUAL_SORTED

Change-Id: Iefb232a501a97a0f0351fd0794c7a3bfc279f98c
Reviewed-on: http://gerrit.sjc.cloudera.com:8080/4513
Reviewed-by: Ippokratis Pandis <ipandis@cloudera.com>
Tested-by: jenkins
IMPALA-1296: Fix DCHECK failure for unnecessary buffered tuple in AnalyticNode

The AnalyticEvalNode had a DCHECK that expected the buffered tuple to
only be set when it was needed (i.e. when there are partition exprs or
order by exprs). However, the FE creates a buffered tuple for an entire
sort group when any AnalyticEvalNodes in the sort group need it and that
tuple is set for all nodes. This reverses the logic so that we DCHECK
the buffered tuple is set when it is needed.

Change-Id: If54b303bc439f235da06a542b46a35c61da9e1bd
Reviewed-on: http://gerrit.sjc.cloudera.com:8080/4489
Reviewed-by: Matthew Jacobs <mj@cloudera.com>
Tested-by: jenkins
Minor cleanups to the commit for IMPALA-1178.

These addressed review feedback from Henry, but I forgot to do a
git add/commit before submitting.  All changes are trivial cleanups.

Change-Id: Ic300a463d4ea6de882dff67ea72033901cac5a25
Reviewed-on: http://gerrit.sjc.cloudera.com:8080/4517
Reviewed-by: Daniel Hecht <dhecht@cloudera.com>
Tested-by: jenkins
Update GRANT/REVOKE test to cleanup all created objects during test cleanup

The tests now cleanup everything in the test cleanup routine. This fixes a flakiness
issue when loading from a snapshot. The problem was that one of the test table's HDFS
path contained old test data since the table wasn't dropped at the end of the test.

Change-Id: Idf50011b0b4ae69e724723c2cede94c9b45d0179
Reviewed-on: http://gerrit.sjc.cloudera.com:8080/4520
Reviewed-by: Lenni Kuff <lskuff@cloudera.com>
Tested-by: jenkins