org.elasticsearch.hadoop.serialization.builder.JdkValueReader Maven / Gradle / Ivy
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch 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.elasticsearch.hadoop.serialization.builder;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.elasticsearch.hadoop.cfg.Settings;
import org.elasticsearch.hadoop.serialization.FieldType;
import org.elasticsearch.hadoop.serialization.Parser;
import org.elasticsearch.hadoop.serialization.Parser.Token;
import org.elasticsearch.hadoop.serialization.SettingsAware;
import org.elasticsearch.hadoop.util.DateUtils;
import org.elasticsearch.hadoop.util.StringUtils;
/**
* Basic value reader handling using the implied JSON type.
*/
public class JdkValueReader implements SettingsAware, ValueReader {
private boolean emptyAsNull = true;
private boolean richDate = true;
@Override
public Object readValue(Parser parser, String value, FieldType esType) {
if (esType == null) {
return nullValue();
}
switch (esType) {
case NULL:
return nullValue();
case STRING:
return textValue(value);
case BYTE:
return byteValue(value, parser);
case SHORT:
return shortValue(value, parser);
case INTEGER:
return intValue(value, parser);
case TOKEN_COUNT:
case LONG:
return longValue(value, parser);
case FLOAT:
return floatValue(value, parser);
case DOUBLE:
return doubleValue(value, parser);
case BOOLEAN:
return booleanValue(value, parser);
case BINARY:
return binaryValue(parser.binaryValue());
case DATE:
return date(value, parser);
case OBJECT:
case NESTED:
// everything else (IP, GEO) gets translated to strings
default:
return textValue(value);
}
}
@Override
public Object createMap() {
return new LinkedHashMap
© 2015 - 2025 Weber Informatics LLC | Privacy Policy