private List analyzeRowFormat()

in fastmodel-transform/fastmodel-transform-hive/src/main/java/com/aliyun/fastmodel/transform/hive/parser/HiveAstBuilder.java [393:433]


    private List<Property> analyzeRowFormat(HiveParser.TableRowFormatContext ctx) {
        if (ctx == null) {
            return Collections.emptyList();
        }
        List<Property> properties = new ArrayList<>();
        if (ctx.rowFormatSerde() != null) {
            HiveParser.RowFormatSerdeContext rowFormatSerdeContext = ctx.rowFormatSerde();
            List<String> children = rowFormatSerdeContext.children.stream()
                    .map(ParseTree::getText).collect(Collectors.toList());
            if (rowFormatSerdeContext.KW_SERDE() != null) {
                // stored as
                int index = children.indexOf(rowFormatSerdeContext.KW_SERDE().getText());
                String value = StripUtils.strip(children.get(index + 1));
                properties.add(new Property(HivePropertyKey.ROW_FORMAT_SERDE.getValue(), new StringLiteral(value)));
            }
            if (rowFormatSerdeContext.tableProperties() != null
                    && rowFormatSerdeContext.tableProperties().tablePropertiesList() != null
                    && CollectionUtils.isNotEmpty(rowFormatSerdeContext.tableProperties().tablePropertiesList().keyValueProperty())) {
                List<KeyValuePropertyContext> keyValuePropertyContexts =
                        rowFormatSerdeContext.tableProperties().tablePropertiesList().keyValueProperty();
                keyValuePropertyContexts.forEach(context -> {
                    String propKey = StripUtils.strip(context.getChild(0).getText());
                    String propValue = StripUtils.strip(context.getChild(2).getText());
                    properties.add(new Property(StringUtils.join(Lists.newArrayList(HivePropertyKey.SERDE_PROPS.getValue(), propKey),
                            "."), new StringLiteral(propValue)));
                });
            }
        }
        if (ctx.rowFormatDelimited() != null) {
            HiveParser.RowFormatDelimitedContext rowFormatDelimitedContext = ctx.rowFormatDelimited();
            if (rowFormatDelimitedContext.tableRowFormatFieldIdentifier() != null) {
                String value = StripUtils.strip(rowFormatDelimitedContext.tableRowFormatFieldIdentifier().stop.getText());
                properties.add(new Property(HivePropertyKey.FIELDS_TERMINATED.getValue(), new StringLiteral(value)));
            }
            if (rowFormatDelimitedContext.tableRowFormatLinesIdentifier() != null) {
                String value = StripUtils.strip(rowFormatDelimitedContext.tableRowFormatLinesIdentifier().stop.getText());
                properties.add(new Property(HivePropertyKey.LINES_TERMINATED.getValue(), new StringLiteral(value)));
            }
        }
        return properties;
    }