Package org.apache.druid.metadata
Class SQLMetadataConnector
java.lang.Object
org.apache.druid.metadata.SQLMetadataConnector
- All Implemented Interfaces:
MetadataStorageConnector
- Direct Known Subclasses:
DerbyConnector
-
Field Summary
Fields inherited from interface org.apache.druid.metadata.MetadataStorageConnector
CONFIG_TABLE_KEY_COLUMN, CONFIG_TABLE_VALUE_COLUMN -
Constructor Summary
ConstructorsConstructorDescriptionSQLMetadataConnector(com.google.common.base.Supplier<MetadataStorageConnectorConfig> config, com.google.common.base.Supplier<MetadataStorageTablesConfig> tablesConfigSupplier, CentralizedDatasourceSchemaConfig centralizedDatasourceSchemaConfig) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidAdds new columns (used_status_last_updated) to the "segments" table.booleancompareAndSwap(List<MetadataCASUpdate> updates) protected booleanVendor specific errors that are not covered byisTransientException(Throwable)voidvoidvoidcreateConfigTable(String tableName) voidvoidcreateDataSourceTable(String tableName) ThedataSourcecolumn stores the supervisor ID.voidcreateEntryTable(String tableName) voidcreateIndex(String tableName, String indexName, List<String> indexCols, Set<String> createdIndexSet) create index on the table with retry if not already exist, to be called after createTablevoidcreateLockTable(String tableName, String entryTypeName) voidvoidcreatePendingSegmentsTable(String tableName) voidvoidcreateRulesTable(String tableName) voidvoidcreateSegmentSchemaTable(String tableName) voidvoidcreateSegmentTable(String tableName) voidvoidcreateSupervisorsTable(String tableName) voidcreateTable(String tableName, Iterable<String> sql) Creates the given table and indexes if the table doesn't already exist.voidvoidvoiddeleteAllRecords(String tableName) The character set and collation for case-sensitive nonbinary string comparisonprotected org.apache.commons.dbcp2.BasicDataSourceabstract org.skife.jdbi.v2.DBIgetDBI()getIndexInfo(DatabaseMetaData databaseMetaData, String tableName) Get the ResultSet for indexInfo for given tablegetIndexOnTable(String tableName) Get the Set of the index on given tableSQL type to use for payload data (e.g.abstract Stringabstract StringAuto-incrementing integer SQL type to use for IDs.abstract intReturns the value that should be passed to statement.setFetchSize to ensure results are streamed back from the database instead of fetching the entire result set in memory.final <T> TinReadOnlyTransaction(org.skife.jdbi.v2.TransactionCallback<T> callback) insertOrUpdate(String tableName, String keyColumn, String valueColumn, String key, byte[] value) protected booleanChecks if the root cause of the given exception is a PacketTooBigException.final booleanabstract StringlimitClause(int limit) byte[]byte[]lookupWithHandle(org.skife.jdbi.v2.Handle handle, String tableName, String keyColumn, String valueColumn, String key) protected static org.apache.commons.dbcp2.BasicDataSourcemakeDatasource(MetadataStorageConnectorConfig connectorConfig, String validationQuery) voidprepareTaskEntryTable(String tableName) final <T> TretryReadOnlyTransaction(org.skife.jdbi.v2.TransactionCallback<T> callback, int quietTries, int maxTries) <T> TretryTransaction(org.skife.jdbi.v2.TransactionCallback<T> callback, int quietTries, int maxTries) <T> TretryWithHandle(org.skife.jdbi.v2.tweak.HandleCallback<T> callback) <T> TretryWithHandle(org.skife.jdbi.v2.tweak.HandleCallback<T> callback, com.google.common.base.Predicate<Throwable> myShouldRetry) abstract booleantableExists(org.skife.jdbi.v2.Handle handle, String tableName) protected booleantableHasColumn(String tableName, String columnName) Checks table metadata to determine if the given column exists in the table.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.druid.metadata.MetadataStorageConnector
exportTable
-
Constructor Details
-
SQLMetadataConnector
public SQLMetadataConnector(com.google.common.base.Supplier<MetadataStorageConnectorConfig> config, com.google.common.base.Supplier<MetadataStorageTablesConfig> tablesConfigSupplier, CentralizedDatasourceSchemaConfig centralizedDatasourceSchemaConfig)
-
-
Method Details
-
getPayloadType
SQL type to use for payload data (e.g. JSON blobs). Must be a binary type, which values can be accessed using ResultSet.getBytes() The resulting string will be interpolated into the table creation statement, e.g.CREATE TABLE druid_table ( payloadNOT NULL, ... ) - Returns:
- String representing the SQL type
-
getCollation
The character set and collation for case-sensitive nonbinary string comparison- Returns:
- the collation for the character set
-
getSerialType
Auto-incrementing integer SQL type to use for IDs. The returned string is interpolated into the table creation statement as follows:CREATE TABLE druid_table ( id <serial-type> NOT NULL, col_2 VARCHAR(255) NOT NULL, col_3 VARCHAR(255) NOT NULL ... )
- Returns:
- String representing auto-incrementing SQL integer type to use for IDs.
-
getStreamingFetchSize
public abstract int getStreamingFetchSize()Returns the value that should be passed to statement.setFetchSize to ensure results are streamed back from the database instead of fetching the entire result set in memory.- Returns:
- optimal fetch size to stream results back
-
getQuoteString
- Returns:
- the string that should be used to quote string fields
-
getValidationQuery
-
tableExists
-
limitClause
-
retryWithHandle
public <T> T retryWithHandle(org.skife.jdbi.v2.tweak.HandleCallback<T> callback, com.google.common.base.Predicate<Throwable> myShouldRetry) -
retryWithHandle
public <T> T retryWithHandle(org.skife.jdbi.v2.tweak.HandleCallback<T> callback) -
retryTransaction
public <T> T retryTransaction(org.skife.jdbi.v2.TransactionCallback<T> callback, int quietTries, int maxTries) -
isTransientException
-
connectorIsTransientException
Vendor specific errors that are not covered byisTransientException(Throwable) -
isRootCausePacketTooBigException
Checks if the root cause of the given exception is a PacketTooBigException.- Returns:
- false by default. Specific implementations should override this method to correctly classify their packet exceptions.
-
createTable
Creates the given table and indexes if the table doesn't already exist. -
createPendingSegmentsTable
-
createDataSourceTable
ThedataSourcecolumn stores the supervisor ID. It has not been renamed to retain backwards compatibility. Supervisors created without an explicit supervisor id default to using the datasource name. -
createSegmentTable
-
createRulesTable
-
createConfigTable
-
prepareTaskEntryTable
-
createEntryTable
-
createLockTable
-
createSupervisorsTable
-
alterSegmentTable
protected void alterSegmentTable()Adds new columns (used_status_last_updated) to the "segments" table. Conditionally, add schema_fingerprint, num_rows columns. -
insertOrUpdate
public Void insertOrUpdate(String tableName, String keyColumn, String valueColumn, String key, byte[] value) - Specified by:
insertOrUpdatein interfaceMetadataStorageConnector
-
compareAndSwap
- Specified by:
compareAndSwapin interfaceMetadataStorageConnector
-
getDBI
public abstract org.skife.jdbi.v2.DBI getDBI() -
createDataSourceTable
public void createDataSourceTable()- Specified by:
createDataSourceTablein interfaceMetadataStorageConnector
-
createPendingSegmentsTable
public void createPendingSegmentsTable()- Specified by:
createPendingSegmentsTablein interfaceMetadataStorageConnector
-
createSegmentTable
public void createSegmentTable()- Specified by:
createSegmentTablein interfaceMetadataStorageConnector
-
createUpgradeSegmentsTable
public void createUpgradeSegmentsTable()- Specified by:
createUpgradeSegmentsTablein interfaceMetadataStorageConnector
-
createRulesTable
public void createRulesTable()- Specified by:
createRulesTablein interfaceMetadataStorageConnector
-
createConfigTable
public void createConfigTable()- Specified by:
createConfigTablein interfaceMetadataStorageConnector
-
createTaskTables
public void createTaskTables()- Specified by:
createTaskTablesin interfaceMetadataStorageConnector
-
createSupervisorsTable
public void createSupervisorsTable()- Specified by:
createSupervisorsTablein interfaceMetadataStorageConnector
-
lookup
- Specified by:
lookupin interfaceMetadataStorageConnector
-
lookupWithHandle
-
getConfig
-
makeDatasource
protected static org.apache.commons.dbcp2.BasicDataSource makeDatasource(MetadataStorageConnectorConfig connectorConfig, String validationQuery) -
getDatasource
protected org.apache.commons.dbcp2.BasicDataSource getDatasource() -
retryReadOnlyTransaction
public final <T> T retryReadOnlyTransaction(org.skife.jdbi.v2.TransactionCallback<T> callback, int quietTries, int maxTries) -
inReadOnlyTransaction
public final <T> T inReadOnlyTransaction(org.skife.jdbi.v2.TransactionCallback<T> callback) -
createAuditTable
public void createAuditTable()- Specified by:
createAuditTablein interfaceMetadataStorageConnector
-
deleteAllRecords
- Specified by:
deleteAllRecordsin interfaceMetadataStorageConnector
-
createSegmentSchemaTable
-
createSegmentSchemasTable
public void createSegmentSchemasTable()- Specified by:
createSegmentSchemasTablein interfaceMetadataStorageConnector
-
getIndexOnTable
Get the Set of the index on given table- Parameters:
tableName- name of the table to fetch the index map- Returns:
- Set of the uppercase index names, returns empty set if table does not exist
-
getIndexInfo
public ResultSet getIndexInfo(DatabaseMetaData databaseMetaData, String tableName) throws SQLException Get the ResultSet for indexInfo for given table- Parameters:
databaseMetaData- DatabaseMetaDatatableName- Name of table- Returns:
- ResultSet with index info
- Throws:
SQLException
-
createIndex
public void createIndex(String tableName, String indexName, List<String> indexCols, Set<String> createdIndexSet) create index on the table with retry if not already exist, to be called after createTable- Parameters:
tableName- Name of the table to create index onindexName- case-insensitive string index name, it helps to check the existing index on tableindexCols- List of columns to be indexed oncreatedIndexSet-
-
tableHasColumn
Checks table metadata to determine if the given column exists in the table.- Returns:
- true if the column exists in the table, false otherwise
-