Java Code Examples for org.apache.phoenix.schema.PTable#getTenantId()

The following examples show how to use org.apache.phoenix.schema.PTable#getTenantId() . 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: SchemaUtil.java    From phoenix with Apache License 2.0 4 votes vote down vote up
public static byte[] getTableKey(PTable dataTable) {
    PName tenantId = dataTable.getTenantId();
    PName schemaName = dataTable.getSchemaName();
    return getTableKey(tenantId == null ? ByteUtil.EMPTY_BYTE_ARRAY : tenantId.getBytes(), schemaName == null ? ByteUtil.EMPTY_BYTE_ARRAY : schemaName.getBytes(), dataTable.getTableName().getBytes());
}
 
Example 2
Source File: UpgradeUtil.java    From phoenix with Apache License 2.0 4 votes vote down vote up
private static boolean isInvalidTableToUpgrade(PTable table) throws SQLException {
    return (table.getType() != PTableType.TABLE || // Must be a table
        table.getTenantId() != null || // Must be global
        !table.getPhysicalName().equals(table.getName())); // Must be the physical table
}
 
Example 3
Source File: UpgradeUtil.java    From phoenix with Apache License 2.0 4 votes vote down vote up
/**
 * Upgrade shared indexes by querying for all that are associated with our
 * physical table.
 * @return true if any upgrades were performed and false otherwise.
 */
private static boolean upgradeSharedIndex(PhoenixConnection upgradeConn, PhoenixConnection globalConn, String physicalName, boolean bypassUpgrade) throws SQLException {
    String query =
            "SELECT TENANT_ID,TABLE_SCHEM,TABLE_NAME\n" + 
            "FROM SYSTEM.CATALOG cat1\n" + 
            "WHERE COLUMN_NAME IS NULL\n" + 
            "AND COLUMN_FAMILY = '" + physicalName + "'\n" + 
            "AND LINK_TYPE = " + LinkType.PHYSICAL_TABLE.getSerializedValue() + "\n" +
            "ORDER BY TENANT_ID";
    ResultSet rs = globalConn.createStatement().executeQuery(query);
    String lastTenantId = null;
    Connection conn = globalConn;
    String url = globalConn.getURL();
    boolean wasUpgraded = false;
    while (rs.next()) {
        String fullTableName = SchemaUtil.getTableName(
                rs.getString(PhoenixDatabaseMetaData.TABLE_SCHEM),
                rs.getString(PhoenixDatabaseMetaData.TABLE_NAME));
        String tenantId = rs.getString(1);
        if (tenantId != null && !tenantId.equals(lastTenantId))  {
            if (lastTenantId != null) {
                conn.close();
            }
            // Open tenant-specific connection when we find a new one
            Properties props = new Properties(globalConn.getClientInfo());
            props.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId);
            conn = DriverManager.getConnection(url, props);
            lastTenantId = tenantId;
        }
        PTable table = PhoenixRuntime.getTable(conn, fullTableName);
        String tableTenantId = table.getTenantId() == null ? null : table.getTenantId().getString();
        if (Objects.equal(lastTenantId, tableTenantId) && !table.rowKeyOrderOptimizable()) {
            upgradeDescVarLengthRowKeys(upgradeConn, globalConn, table.getSchemaName().getString(), table.getTableName().getString(), false, bypassUpgrade);
            wasUpgraded = true;
        }
    }
    rs.close();
    if (lastTenantId != null) {
        conn.close();
    }
    return wasUpgraded;
}