SingleStoreDB I/O
管道選項和有關使用和執行 SingleStoreDB I/O 的一般資訊。
開始之前
若要使用 SingleStoreDB I/O,請將 Maven 成品相依性新增至您的 pom.xml
檔案。
其他資源
驗證
設定 SingleStoreIO 連線屬性需要 DataSource 設定。
建立 DataSource 設定
參數可以是
.create(端點)
- SingleStoreDB 的主機名稱或 IP 位址,格式為 host:[port] (port 是選用的)。
- 必要參數。
- 範例:
.create("myHost:3306")
。
.withUsername(使用者名稱)
- SingleStoreDB 使用者名稱。
- 預設值 -
root
。 - 範例:
.withUsername("USERNAME")
。
.withPassword(密碼)
- SingleStoreDB 使用者的密碼。
- 預設值 - 空字串。
- 範例:
.withPassword("PASSWORD")
。
.withDatabase(資料庫)
- 要使用的 SingleStoreDB 資料庫名稱。
- 範例:
.withDatabase("MY_DATABASE")
。
.withConnectionProperties(連線屬性)
- JDBC 驅動程式使用的屬性清單。
- 格式為「key1=value1;key2=value2;…」。
- 完整的支援屬性清單可在此處找到。
- 範例:
.withConnectionProperties("connectTimeout=30000;useServerPrepStmts=FALSE")
。
注意 - .readWithPartitions()
需要 .withDatabase(...)
。
從 SingleStoreDB 讀取
SingleStoreIO 的其中一個功能是從 SingleStoreDB 資料表讀取。SingleStoreIO 支援兩種讀取類型
- 循序資料讀取 (
.read()
) - 平行資料讀取 (
.readWithPartitions()
)
在許多情況下,由於效能原因,平行資料讀取優於循序資料讀取。
循序資料讀取
基本的 .read()
操作使用方式如下
參數可以是
.withDataSourceConfiguration(dataSourceConfiguration)
- 具有建立資料庫連線所需的所有資訊的
DataSourceConfiguration
物件。如需詳細資訊,請參閱驗證。 - 必要參數。
- 具有建立資料庫連線所需的所有資訊的
.withTable(資料表)
- 要從中讀取資料的資料表。
- 範例:
.withTable("MY_TABLE")
。
.withQuery(查詢)
- 要執行的 SQL 查詢。
- 範例:
.withTable("SELECT * FROM MY_TABLE")
。
.withStatementPreparator(statementPreparator)
.withRowMapper(rowMapper)
- RowMapper 物件。
- 必要參數。
.withOutputParallelization(outputParallelization)
- 布林值,指出是否重新混洗結果。
- 預設值 -
true
。 - 範例:
.withOutputParallelization(true)
。
注意 - 必須使用 .withTable(...)
或 .withQuery(...)
其中之一。
平行資料讀取
基本的 .readWithPartitions()
操作使用方式如下
參數可以是
.withDataSourceConfiguration(dataSourceConfiguration)
- 具有建立資料庫連線所需的所有資訊的
DataSourceConfiguration
物件。如需詳細資訊,請參閱DataSource 設定。 - 必要參數。
- 具有建立資料庫連線所需的所有資訊的
.withTable(資料表)
- 要從中讀取資料的資料表。
- 範例:
.withTable("MY_TABLE")
。
.withQuery(查詢)
- 要執行的 SQL 查詢。
- 範例:
.withTable("SELECT * FROM MY_TABLE")
。
.withRowMapper(rowMapper)
- RowMapper 物件。
- 必要參數。
注意 - 必須使用 .withTable(...)
或 .withQuery(...)
其中之一。
StatementPreparator
StatementPreparator
由 read()
用來設定 PreparedStatement
的參數。例如
RowMapper
RowMapper
由 read()
和 readWithPartitions()
用於將 ResultSet
的每一列轉換為產生的 PCollection
的元素。例如
寫入 SingleStoreDB 資料表
SingleStoreIO 的其中一個功能是寫入 SingleStoreDB 資料表。此轉換使您能夠將使用者的 PCollection 傳送到您的 SingleStoreDB 資料庫。它會傳回每一批元素寫入的列數。
基本的 .write()
操作使用方式如下
參數可以是
.withDataSourceConfiguration(dataSourceConfiguration)
- 具有建立資料庫連線所需的所有資訊的
DataSourceConfiguration
物件。如需詳細資訊,請參閱DataSource 設定。 - 必要參數。
- 具有建立資料庫連線所需的所有資訊的
.withTable(資料表)
- 應該在其中儲存資料的資料表。
- 必要參數。
- 範例:
.withTable("MY_TABLE")
。
.withBatchSize(批次大小)
- 一個
LOAD DATA
查詢載入的列數。 - 預設值 - 100000。
- 範例:
.withBatchSize(100000)
。
- 一個
.withUserDataMapper(userDataMapper)
- UserDataMapper 物件。
- 必要參數。
UserDataMapper
在 write()
操作儲存資料之前,需要 UserDataMapper
將資料從 PCollection
對應到 String
值的陣列。例如
上次更新於 2024/10/31
您是否找到您要找的所有內容?
這一切是否有用且清楚?您想要變更任何內容嗎?請告訴我們!