Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  *
0009  *    http://www.apache.org/licenses/LICENSE-2.0
0010  *
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 package org.apache.spark.sql.catalyst.expressions;
0019 
0020 import org.apache.spark.sql.types.*;
0021 
0022 public final class SpecializedGettersReader {
0023   private SpecializedGettersReader() {}
0024 
0025   public static Object read(
0026       SpecializedGetters obj,
0027       int ordinal,
0028       DataType dataType,
0029       boolean handleNull,
0030       boolean handleUserDefinedType) {
0031     if (handleNull && (obj.isNullAt(ordinal) || dataType instanceof NullType)) {
0032       return null;
0033     }
0034     if (dataType instanceof BooleanType) {
0035       return obj.getBoolean(ordinal);
0036     }
0037     if (dataType instanceof ByteType) {
0038       return obj.getByte(ordinal);
0039     }
0040     if (dataType instanceof ShortType) {
0041       return obj.getShort(ordinal);
0042     }
0043     if (dataType instanceof IntegerType) {
0044       return obj.getInt(ordinal);
0045     }
0046     if (dataType instanceof LongType) {
0047       return obj.getLong(ordinal);
0048     }
0049     if (dataType instanceof FloatType) {
0050       return obj.getFloat(ordinal);
0051     }
0052     if (dataType instanceof DoubleType) {
0053       return obj.getDouble(ordinal);
0054     }
0055     if (dataType instanceof StringType) {
0056       return obj.getUTF8String(ordinal);
0057     }
0058     if (dataType instanceof DecimalType) {
0059       DecimalType dt = (DecimalType) dataType;
0060       return obj.getDecimal(ordinal, dt.precision(), dt.scale());
0061     }
0062     if (dataType instanceof DateType) {
0063       return obj.getInt(ordinal);
0064     }
0065     if (dataType instanceof TimestampType) {
0066       return obj.getLong(ordinal);
0067     }
0068     if (dataType instanceof CalendarIntervalType) {
0069       return obj.getInterval(ordinal);
0070     }
0071     if (dataType instanceof BinaryType) {
0072       return obj.getBinary(ordinal);
0073     }
0074     if (dataType instanceof StructType) {
0075       return obj.getStruct(ordinal, ((StructType) dataType).size());
0076     }
0077     if (dataType instanceof ArrayType) {
0078       return obj.getArray(ordinal);
0079     }
0080     if (dataType instanceof MapType) {
0081       return obj.getMap(ordinal);
0082     }
0083     if (handleUserDefinedType && dataType instanceof UserDefinedType) {
0084       return obj.get(ordinal, ((UserDefinedType)dataType).sqlType());
0085     }
0086 
0087     throw new UnsupportedOperationException("Unsupported data type " + dataType.simpleString());
0088   }
0089 }