ALINK(十一):載入資料集 (四)Table資料讀入 (TableSourceBatchOp)
阿新 • • 發佈:2021-06-15
Java 類名:com.alibaba.alink.operator.batch.source.TableSourceBatchOp
Python 類名:TableSourceBatchOp
功能介紹
從Table中生成BatchOperator資料
引數說明
名稱 |
中文名稱 |
描述 |
型別 |
是否必須? |
預設值 |
程式碼示例
Python 程式碼
from pyalink.alink import * import pandas as pd useLocalEnv(1) df = pd.DataFrame([ [0, "0 0 0"], [1, "1 1 1"], [2, "2 2 2"] ]) inOp = BatchOperator.fromDataframe(df, schemaStr='id int, vec string') inOp.getOutputTable() TableSourceBatchOp(inOp.getOutputTable()).print()
Java 程式碼
import org.apache.flink.types.Row; import com.alibaba.alink.operator.batch.BatchOperator; import com.alibaba.alink.operator.batch.source.MemSourceBatchOp;import com.alibaba.alink.operator.batch.source.TableSourceBatchOp; import org.junit.Test; import java.util.Arrays; import java.util.List; public class TableSourceBatchOpTest { @Test public void testTableSourceBatchOp() throws Exception { List <Row> df = Arrays.asList( Row.of(0, "0 0 0"), Row.of(1, "1 1 1"), Row.of(2, "2 2 2") ); BatchOperator <?> inOp = new MemSourceBatchOp(df, "id int, vec string"); inOp.getOutputTable(); new TableSourceBatchOp(inOp.getOutputTable()).print(); } }
執行結果
id |
vec |
0 |
0 0 0 |
1 |
1 1 1 |
2 |
2 2 2 |