hadoop中空值显示0
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hadoop中空值显示0相关的知识,希望对你有一定的参考价值。
参考技术A 可以尝试以下步骤解决:1 ,分别删除:主节点从节点的 /usr/local/hadoop-2.6.2/etc/tmp
2: 编辑cd usr/local/hadoop-2.6.2/etc/hadoop/ vi slaves
删除slaves里面的 localhost
3:然后 hadoop namenode -format
4: 重新启动 start-all.sh 参考技术B 答:去到所有从节的/hadoop/tmp/dfs/data/current/目录中,同样将目录中的VERSION文件利用编辑器.
hadoop集群启动成功但进入管理界面显示DataNode为0的问题总结 - 爱...
如何处理枚举中空值的 InvalidFormatException
【中文标题】如何处理枚举中空值的 InvalidFormatException【英文标题】:How to handle InvalidFormatException for empty values on enumerations 【发布时间】:2021-09-02 00:09:57 【问题描述】:。当一个空值被传递给底层的杰克逊解析器而不是一个低级错误时,我们想抛出一个验证错误。我们怎样才能避免这种情况?
Exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `com.company.model.Flower` from String "": not one of the values accepted for Enum class: [Lilly, Jasmine]
at [Source: (PushbackInputStream); line: 1, column: 64]
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:389)
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.read(AbstractJackson2HttpMessageConverter.java:342)
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:186)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:158)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:131)
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121)
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:170)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:894)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1060)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:962)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
at org.springframework.web.servlet.FrameworkServlet.doPut(FrameworkServlet.java:920)
【问题讨论】:
【参考方案1】:假设您的 jackson-databind 版本 >= 2.12.0, 参考this article - Jackson 2.12 Most Wanted (4/5): CoercionConfig system
你可以在ObjectMapper
中添加一个配置bean来添加枚举的强制设置,这样空字符串就会被映射为null,然后在对应的枚举属性中添加@NotNull
注解就可以解决问题了。
import com.fasterxml.jackson.databind.cfg.CoercionAction;
import com.fasterxml.jackson.databind.cfg.CoercionInputShape;
import com.fasterxml.jackson.databind.type.LogicalType;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ObjectMapperConfig
@Bean
public Jackson2ObjectMapperBuilderCustomizer jsonCustomizer()
return builder -> builder.postConfigurer(objectMapper ->
objectMapper.coercionConfigFor(LogicalType.Enum)
.setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsNull);
);
【讨论】:
以上是关于hadoop中空值显示0的主要内容,如果未能解决你的问题,请参考以下文章