org.elasticsearch.hadoop.serialization.builder.JdkValueReader Maven / Gradle / Ivy
                 Go to download
                
        
                    Show more of this group  Show more artifacts with this name
Show all versions of elasticsearch-spark-20_2.10 Show documentation
                Show all versions of elasticsearch-spark-20_2.10 Show documentation
Elasticsearch Spark (for Spark 2.X)
                
            /*
 * 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.Arrays;
import java.util.Collection;
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.serialization.field.FieldFilter;
import org.elasticsearch.hadoop.serialization.field.FieldFilter.NumberedInclude;
import org.elasticsearch.hadoop.serialization.field.FieldFilter.Result;
import org.elasticsearch.hadoop.util.DateUtils;
import org.elasticsearch.hadoop.util.SettingsUtils;
import org.elasticsearch.hadoop.util.StringUtils;
import org.elasticsearch.hadoop.util.unit.Booleans;
/**
 * Basic value reader handling using the implied JSON type.
 */
public class JdkValueReader implements SettingsAware, ValueReader {
    private boolean emptyAsNull = true;
    private boolean richDate = true;
    protected Collection arrayInclude = Collections. emptyList();
    protected Collection arrayExclude = Collections.emptyList();
    protected String currentFieldName;
    protected int nestedArrayLevel = 0;
    @Override
    public Object readValue(Parser parser, String value, FieldType esType) {
        if (esType == null) {
            return nullValue();
        }
        switch (esType) {
        case NULL:
            return nullValue();
        case STRING:
        case TEXT:
        case KEYWORD:
            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 HALF_FLOAT:
        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);
            // catch-all - exists really for the other custom types that might be introduced
            // compound types should have been handled earlier in the stream
        default:
            return textValue(value);
        }
    }
    @Override
    public Object createMap() {
        return new LinkedHashMap       © 2015 - 2025 Weber Informatics LLC | Privacy Policy