-
Notifications
You must be signed in to change notification settings - Fork 39
/
TableSourceHelper.java
51 lines (43 loc) · 1.75 KB
/
TableSourceHelper.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.getindata.connectors.http.internal.table.lookup;
import java.util.Collections;
import java.util.List;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.flink.table.data.GenericRowData;
import org.apache.flink.table.data.RowData;
import org.apache.flink.table.types.DataType;
import org.apache.flink.table.types.logical.LogicalType;
import org.apache.flink.table.types.logical.LogicalTypeRoot;
import org.apache.flink.table.types.logical.utils.LogicalTypeChecks;
import static org.apache.flink.table.types.logical.utils.LogicalTypeChecks.isCompositeType;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class TableSourceHelper {
/**
* Returns the first-level field names for the provided {@link DataType}.
*
* <p>Note: This method returns an empty list for every {@link DataType} that is not a
* composite
* type.
*/
public static List<String> getFieldNames(DataType dataType) {
final LogicalType type = dataType.getLogicalType();
if (type.getTypeRoot() == LogicalTypeRoot.DISTINCT_TYPE) {
return getFieldNames(dataType.getChildren().get(0));
} else if (isCompositeType(type)) {
return LogicalTypeChecks.getFieldNames(type);
}
return Collections.emptyList();
}
/**
* Builds {@link RowData} object based on provided list of values.
* @param values values to use as {@link RowData} column values.
* @return new {@link RowData} instance.
*/
public static RowData buildGenericRowData(List<Object> values) {
GenericRowData row = new GenericRowData(values.size());
for (int i = 0; i < values.size(); ++i) {
row.setField(i, values.get(i));
}
return row;
}
}