Returns selected columns as a boolean array with true value set for specified column names. The result will contain number of elements equal to flattened number of columns. For example: selectedColumns - a,b,c allColumns - a,b,c,d If column c is a complex type, say list<string> and other types
(String selectedColumns,
TypeDescription schema)
| 53 | * @return - boolean array with true value set for the specified column names |
| 54 | */ |
| 55 | public static boolean[] includeColumns(String selectedColumns, |
| 56 | TypeDescription schema) { |
| 57 | int numFlattenedCols = schema.getMaximumId(); |
| 58 | boolean[] results = new boolean[numFlattenedCols + 1]; |
| 59 | if ("*".equals(selectedColumns)) { |
| 60 | Arrays.fill(results, true); |
| 61 | return results; |
| 62 | } |
| 63 | TypeDescription baseSchema = SchemaEvolution.checkAcidSchema(schema) ? |
| 64 | SchemaEvolution.getBaseRow(schema) : schema; |
| 65 | |
| 66 | if (selectedColumns != null && |
| 67 | baseSchema.getCategory() == TypeDescription.Category.STRUCT) { |
| 68 | |
| 69 | for (String columnName : selectedColumns.split(COMMA_STR)) { |
| 70 | TypeDescription column = findColumn(baseSchema, columnName.trim()); |
| 71 | if (column != null) { |
| 72 | for (int i = column.getId(); i <= column.getMaximumId(); ++i) { |
| 73 | results[i] = true; |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | return results; |
| 79 | } |
| 80 | |
| 81 | private static TypeDescription findColumn(TypeDescription schema, String column) { |
| 82 | TypeDescription result = schema; |