Amazon Redshift non supporterà più l'uso delle UDF Python dopo il 30 giugno 2026. Inizieremo ad applicarlo per fasi. Per ulteriori informazioni sulla fine del ciclo di vita e sulle opzioni di migrazione di Python, consulta il post del
Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.
Usa l'API per i metadati dei driver di Amazon Redshift per applicazioni e strumenti
Per le applicazioni e gli strumenti che si connettono ad Amazon Redshift, come uno strumento di business intelligence o un editor di query, ti consigliamo di utilizzare l'API dei metadati dei driver fornita dai driver Amazon Redshift JDBC 2.x , ODBC 2.x o Python per scoprire i metadati sugli oggetti del tuo data warehouse, inclusi database, schemi, tabelle, colonne e tipi di dati. In alternativa, puoi utilizzare i comandi di Amazon Redshift. SHOW
Utilizza l'API dei metadati dei driver per i seguenti vantaggi:
-
Specification-compliant. I driver JDBC e ODBC implementano interfacce di metadati standard (
DatabaseMetaDatain JDBC e in ODBC).SQLTablesSQLColumnsPoiché Python DB-API (PEP 249) non definisce una specifica API per i metadati, il driver Amazon Redshift Python segue le specifiche JDBC, fornendo metodi equivalenti come,, e. DatabaseMetaDataget_tables()get_columns()get_schemas()Queste API seguono specifiche ben definite, quindi il codice di integrazione è portabile. Man mano che Amazon Redshift evolve le sue tabelle di sistema interne, l'applicazione non deve cambiare. -
Performance-optimized. L'API dei metadati dei driver è ottimizzata per restituire i metadati in modo efficiente. AWS continua a investire nelle prestazioni delle API per i metadati dei driver.
-
Forward-compatible. Amazon Redshift è conforme alle specifiche dei connettori JDBC, ODBC e Python. Quando codifichi utilizzando queste API standard, l'applicazione è protetta dalle modifiche alla struttura sottostante del catalogo di sistema.
Esempio: utilizzo di JDBC DatabaseMetaData.getTables () per recuperare i metadati della tabella
DatabaseMetaData dbmd = connection.getMetaData(); // getTables(catalog, schemaPattern, tableNamePattern, types) // catalog: "test" — filters to the database named "test" // schemaPattern: "test_pattern" — filters schemas matching this pattern (supports SQL wildcards % and _) // tableNamePattern: null — no filter, returns all table names // types: {"TABLE", "EXTERNAL TABLE"} — only return regular tables and external tables ResultSet rs = dbmd.getTables("test", "test_pattern", null, new String[] {"TABLE", "EXTERNAL TABLE"});
Esempio: utilizzo del cursor.get_columns () in Python per recuperare i metadati delle colonne
cursor: redshift_connector.Cursor = conn.cursor() # get_columns(catalog, schema_pattern, table_name_pattern, column_name_pattern) # catalog: 'test' — filters to the database named "test" # schema_pattern: 'test_pattern' — filters schemas matching this pattern (supports SQL wildcards % and _) # table_name_pattern: 'testabc' — filters to the table named "testabc" # column_name_pattern: '%' — wildcard, returns all columns in the matching table result: tuple = cursor.get_columns('test', 'test_pattern', 'testabc', '%')
Esempio: utilizzo di ODBC () per recuperare i metadati della chiave primaria SQLPrimaryKeys
// SQLPrimaryKeys(hstmt, catalog, catalog_len, schema, schema_len, table, table_len) // catalog: "test" — filters to the database named "test" // schema: "test_schema" — filters to the schema named "test_schema" // table: "test_table" — retrieves primary key columns for this table // Note: Unlike getTables/getColumns, SQLPrimaryKeys does NOT support wildcard patterns. retcode = SQLPrimaryKeys(hstmt, (SQLCHAR *)"test", SQL_NTS, (SQLCHAR *)"test_schema", SQL_NTS, (SQLCHAR *)"test_table", SQL_NTS); while (SQL_SUCCEEDED(retcode = SQLFetch(hstmt))) { for (i = 1; i <= columns; i++) { retcode = SQLGetData(hstmt, i, SQL_C_CHAR, buf, sizeof(buf), &indicator); } }
Esempio: utilizzo di ODBC SQLTables () per elencare database e schemi
L'API ODBC non fornisce funzioni separate per elencare cataloghi o schemi. Si utilizzano invece speciali convenzioni di chiamata SQLTables() per recuperare queste informazioni.
Per elencare tutti i database (cataloghi)
Chiama SQLTables() con CatalogName set to. SQL_ALL_CATALOGS Imposta SchemaName e TableName svuota le stringhe. Il set di risultati restituisce valori validi solo nella TABLE_CAT colonna. Tutte le altre colonne contengono valori NULL.
// List all catalogs (databases) available on the data source. retcode = SQLTables(hstmt, (SQLCHAR *)SQL_ALL_CATALOGS, SQL_NTS, // CatalogName = "%" (SQL_ALL_CATALOGS) (SQLCHAR *)"", 0, // SchemaName = "" (empty string) (SQLCHAR *)"", 0, // TableName = "" (empty string) NULL, 0); // TableType = NULL (not filtered)
Per elencare tutti gli schemi
Chiama SQLTables() con SchemaName set to. SQL_ALL_SCHEMAS Imposta CatalogName e TableName svuota le stringhe.
// List all schemas available on the data source. retcode = SQLTables(hstmt, (SQLCHAR *)"", 0, // CatalogName = "" (empty string) (SQLCHAR *)SQL_ALL_SCHEMAS, SQL_NTS, // SchemaName = "%" (SQL_ALL_SCHEMAS) (SQLCHAR *)"", 0, // TableName = "" (empty string) NULL, 0); // TableType = NULL (not filtered)
Nota
La specifica ODBC definisce solo TABLE_SCHEM come valido per l'enumerazione dello schema. Amazon Redshift viene compilato anche TABLE_CAT perché supporta il rilevamento di metadati tra database e ogni schema è associato a un database specifico.