Java Code Examples for org.apache.phoenix.query.QueryConstants#UNSET_TIMESTAMP
The following examples show how to use
org.apache.phoenix.query.QueryConstants#UNSET_TIMESTAMP .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StatementContext.java From phoenix with Apache License 2.0 | 6 votes |
public long getCurrentTime() throws SQLException { long ts = this.getCurrentTable().getTimeStamp(); if (ts != QueryConstants.UNSET_TIMESTAMP) { return ts; } if (currentTime != QueryConstants.UNSET_TIMESTAMP) { return currentTime; } /* * For an UPSERT VALUES where autocommit off, we won't hit the server until the commit. * However, if the statement has a CURRENT_DATE() call as a value, we need to know the * current time at execution time. In that case, we'll call MetaDataClient.updateCache * purely to bind the current time based on the server time. */ PTable table = this.getCurrentTable().getTable(); PhoenixConnection connection = getConnection(); MetaDataClient client = new MetaDataClient(connection); currentTime = client.getCurrentTime(table.getSchemaName().getString(), table.getTableName().getString()); return currentTime; }
Example 2
Source File: StatementContext.java From phoenix with Apache License 2.0 | 6 votes |
public long getCurrentTime() throws SQLException { long ts = this.getCurrentTable().getCurrentTime(); // if the table is transactional then it is only resolved once per query, so we can't use the table timestamp if (this.getCurrentTable().getTable().getType() != PTableType.SUBQUERY && this.getCurrentTable().getTable().getType() != PTableType.PROJECTED && !this.getCurrentTable().getTable().isTransactional() && ts != QueryConstants.UNSET_TIMESTAMP) { return ts; } if (currentTime != QueryConstants.UNSET_TIMESTAMP) { return currentTime; } /* * For an UPSERT VALUES where autocommit off, we won't hit the server until the commit. * However, if the statement has a CURRENT_DATE() call as a value, we need to know the * current time at execution time. In that case, we'll call MetaDataClient.updateCache * purely to bind the current time based on the server time. */ PTable table = this.getCurrentTable().getTable(); PhoenixConnection connection = getConnection(); MetaDataClient client = new MetaDataClient(connection); currentTime = client.getCurrentTime(table.getSchemaName().getString(), table.getTableName().getString()); return currentTime; }
Example 3
Source File: TableRef.java From phoenix with Apache License 2.0 | 5 votes |
public TableRef(String alias, PTable table, long upperBoundTimeStamp, long lowerBoundTimeStamp, boolean hasDynamicCols) { this.alias = alias; this.table = table; // if UPDATE_CACHE_FREQUENCY is set, always let the server set timestamps this.upperBoundTimeStamp = table.getUpdateCacheFrequency()!=0 ? QueryConstants.UNSET_TIMESTAMP : upperBoundTimeStamp; this.currentTime = this.upperBoundTimeStamp; this.lowerBoundTimeStamp = lowerBoundTimeStamp; this.hasDynamicCols = hasDynamicCols; }
Example 4
Source File: MetaDataClient.java From phoenix with Apache License 2.0 | 4 votes |
private MetaDataMutationResult updateCache(PName tenantId, String schemaName, String tableName, boolean alwaysHitServer) throws SQLException { // TODO: pass byte[] herez long clientTimeStamp = getClientTimeStamp(); boolean systemTable = SYSTEM_CATALOG_SCHEMA.equals(schemaName); // System tables must always have a null tenantId tenantId = systemTable ? null : tenantId; PTable table = null; String fullTableName = SchemaUtil.getTableName(schemaName, tableName); long tableTimestamp = HConstants.LATEST_TIMESTAMP; try { table = connection.getMetaDataCache().getTable(new PTableKey(tenantId, fullTableName)); tableTimestamp = table.getTimeStamp(); } catch (TableNotFoundException e) { } // Don't bother with server call: we can't possibly find a newer table if (table != null && !alwaysHitServer && (systemTable || tableTimestamp == clientTimeStamp - 1)) { return new MetaDataMutationResult(MutationCode.TABLE_ALREADY_EXISTS,QueryConstants.UNSET_TIMESTAMP,table); } int maxTryCount = tenantId == null ? 1 : 2; int tryCount = 0; MetaDataMutationResult result; do { final byte[] schemaBytes = PVarchar.INSTANCE.toBytes(schemaName); final byte[] tableBytes = PVarchar.INSTANCE.toBytes(tableName); result = connection.getQueryServices().getTable(tenantId, schemaBytes, tableBytes, tableTimestamp, clientTimeStamp); if (SYSTEM_CATALOG_SCHEMA.equals(schemaName)) { return result; } MutationCode code = result.getMutationCode(); PTable resultTable = result.getTable(); // We found an updated table, so update our cache if (resultTable != null) { // Cache table, even if multi-tenant table found for null tenant_id // These may be accessed by tenant-specific connections, as the // tenant_id will always be added to mask other tenants data. // Otherwise, a tenant would be required to create a VIEW first // which is not really necessary unless you want to filter or add // columns addTableToCache(result); return result; } else { // if (result.getMutationCode() == MutationCode.NEWER_TABLE_FOUND) { // TODO: No table exists at the clientTimestamp, but a newer one exists. // Since we disallow creation or modification of a table earlier than the latest // timestamp, we can handle this such that we don't ask the // server again. if (table != null) { // Ensures that table in result is set to table found in our cache. result.setTable(table); if (code == MutationCode.TABLE_ALREADY_EXISTS) { // Although this table is up-to-date, the parent table may not be. // In this case, we update the parent table which may in turn pull // in indexes to add to this table. if (addIndexesFromPhysicalTable(result)) { connection.addTable(result.getTable()); } return result; } // If table was not found at the current time stamp and we have one cached, remove it. // Otherwise, we're up to date, so there's nothing to do. if (code == MutationCode.TABLE_NOT_FOUND && tryCount + 1 == maxTryCount) { connection.removeTable(tenantId, fullTableName, table.getParentName() == null ? null : table.getParentName().getString(), table.getTimeStamp()); } } } tenantId = null; // Try again with global tenantId } while (++tryCount < maxTryCount); return result; }
Example 5
Source File: MutationState.java From phoenix with Apache License 2.0 | 4 votes |
public static long getTableTimestamp(final Long tableTimestamp, Long scn) { return (tableTimestamp != null && tableTimestamp != QueryConstants.UNSET_TIMESTAMP) ? tableTimestamp : (scn == null ? HConstants.LATEST_TIMESTAMP : scn); }
Example 6
Source File: TableRef.java From phoenix with Apache License 2.0 | 4 votes |
public TableRef(PTable table) { this(null, table, QueryConstants.UNSET_TIMESTAMP, false); }