Hive+Spring Boot2不包括标准字段

5us2dqdw  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(314)

我使用Hive和Spring Boot。

<dependency>
        <groupId>io.honeycomb.beeline</groupId>
        <artifactId>beeline-spring-boot-starter</artifactId>
        <version>1.0.2</version>
    </dependency>

我能够成功地将数据发送到Hive,但默认情况下,beeline/spring正在发送标准字段,如“request.path”、“request.header…”、“request…”等。。。
如何将这些标准字段中的部分或全部排除在记录/发送到honeycomb的范围之外?
任何代码/配置示例都很有用。

lstz6jyr

lstz6jyr1#

好的,所以我必须创建eventpostprocessor并删除我感兴趣的标准字段。。。我希望这是正确的方法!

@Configuration
public class HoneycombConfig {

@Bean
public EventPostProcessor honeycombEventPostProcessor(HoneycombDependencyConfig honeycombDependencyConfig) {
    return new ApplicationHoneycombEventPostProcessor(honeycombDependencyConfig.getExcludeFields());
}

static class ApplicationHoneycombEventPostProcessor implements EventPostProcessor {

    private final List<String> excludeFields;

    public ApplicationHoneycombEventPostProcessor(List<String> excludeFields) {
        this.excludeFields = excludeFields;
    }

    @Override
    public void process(EventData<?> eventData) {
        //over write field
        this.excludeFields
                .stream()
                .filter(field -> eventData.getFields().containsKey(field))
                .forEach(field -> eventData.getFields().remove(field));
    }
}

}

@Configuration
@ConfigurationProperties(prefix = "dependencies.honeycomb")
public class HoneycombDependencyConfig {

private List<String> excludeFields;

public List<String> getExcludeFields() {
    if(this.excludeFields == null) {
         this.excludeFields = new ArrayList<>();
    }
    return excludeFields;
}

public void setExcludeFields(List<String> excludeFields) {
    this.excludeFields = excludeFields;
}

}

相关问题