rdblue commented on code in PR #4525: URL: https://github.com/apache/iceberg/pull/4525#discussion_r863327544
########## core/src/main/java/org/apache/iceberg/DefaultValueParser.java: ########## @@ -0,0 +1,253 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.iceberg; + +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.fasterxml.jackson.databind.ser.std.ByteBufferSerializer; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.time.LocalDateTime; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; +import org.apache.iceberg.exceptions.ValidationException; +import org.apache.iceberg.expressions.Literal; +import org.apache.iceberg.relocated.com.google.common.base.Preconditions; +import org.apache.iceberg.relocated.com.google.common.collect.Lists; +import org.apache.iceberg.relocated.com.google.common.collect.Maps; +import org.apache.iceberg.relocated.com.google.common.io.BaseEncoding; +import org.apache.iceberg.types.Type; +import org.apache.iceberg.types.Types; + +public class DefaultValueParser { + private DefaultValueParser() { + } + + private static final JsonFactory FACTORY = new JsonFactory(); + private static final ObjectMapper MAPPER; + + static { + MAPPER = new ObjectMapper(FACTORY); + SimpleModule customModule = new SimpleModule(); + customModule.addSerializer(ByteBuffer.class, new HexStringCustomByteBufferSerializer()); + MAPPER.registerModule(customModule); + } + + public static ObjectMapper mapper() { + return MAPPER; + } + + public static Object parseDefaultFromJson(Type type, JsonNode jsonNode) { + if (jsonNode == null) { + return null; + } + + switch (type.typeId()) { + case BOOLEAN: + return jsonNode.booleanValue(); Review Comment: I think this should use the same pattern and checks that are used in other JSON parsers. Those use `JsonUtil` and validate the type. For example: ```java public static int getInt(String property, JsonNode node) { Preconditions.checkArgument(node.has(property), "Cannot parse missing int %s", property); JsonNode pNode = node.get(property); Preconditions.checkArgument(pNode != null && !pNode.isNull() && pNode.isNumber(), "Cannot parse %s to an integer value: %s", property, pNode); return pNode.asInt(); } ``` That checks that the node actually is an integer. We want to be similarly strict here. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
