Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* 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.hadoop.hive.serde2.lazy;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hive.serde2.lazy.objectinspector.LazyMapObjectInspector;
import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
import org.apache.hadoop.io.Text;
/**
* LazyMap stores a map of Primitive LazyObjects to LazyObjects. Note that the
* keys of the map cannot contain null.
*
* LazyMap does not deal with the case of a NULL map. That is handled by the
* parent LazyObject.
*/
public class LazyMap extends LazyNonPrimitive {
public static final Log LOG = LogFactory.getLog(LazyMap.class);
/**
* Whether the data is already parsed or not.
*/
boolean parsed = false;
/**
* The size of the map. Only valid when the data is parsed. -1 when the map is
* NULL.
*/
int mapSize = 0;
/**
* The beginning position of key[i]. Only valid when the data is parsed. Note
* that keyStart[mapSize] = begin + length + 1; that makes sure we can use the
* same formula to compute the length of each value in the map.
*/
int[] keyStart;
/**
* The end position of key[i] (the position of the key-value separator). Only
* valid when the data is parsed.
*/
int[] keyEnd;
/**
* The length of value[i].
*/
int[] valueLength;
/**
* The keys are stored in an array of LazyPrimitives.
*/
LazyPrimitive, ?>[] keyObjects;
/**
* Whether init() is called on keyObjects[i].
*/
boolean[] keyInited;
/**
* The values are stored in an array of LazyObjects. value[index] will start
* from KeyEnd[index] + 1, and ends before KeyStart[index+1] - 1.
*/
LazyObject[] valueObjects;
/**
* Whether init() is called on valueObjects[i].
*/
boolean[] valueInited;
/**
* Construct a LazyMap object with the ObjectInspector.
*/
protected LazyMap(LazyMapObjectInspector oi) {
super(oi);
}
/**
* Set the row data for this LazyArray.
*
* @see LazyObject#init(ByteArrayRef, int, int)
*/
@Override
public void init(ByteArrayRef bytes, int start, int length) {
super.init(bytes, start, length);
parsed = false;
cachedMap = null;
keyStart = null;
}
/**
* Enlarge the size of arrays storing information for the elements inside the
* array.
*/
protected void enlargeArrays() {
if (keyStart == null) {
int initialSize = 2;
keyStart = new int[initialSize];
keyEnd = new int[initialSize];
valueLength = new int[initialSize];
keyObjects = new LazyPrimitive, ?>[initialSize];
valueObjects = new LazyObject[initialSize];
keyInited = new boolean[initialSize];
valueInited = new boolean[initialSize];
} else {
keyStart = Arrays.copyOf(keyStart, keyStart.length * 2);
keyEnd = Arrays.copyOf(keyEnd, keyEnd.length * 2);
valueLength = Arrays.copyOf(valueLength, valueLength.length * 2);
keyObjects = Arrays.copyOf(keyObjects, keyObjects.length * 2);
valueObjects = Arrays.copyOf(valueObjects, valueObjects.length * 2);
keyInited = Arrays.copyOf(keyInited, keyInited.length * 2);
valueInited = Arrays.copyOf(valueInited, valueInited.length * 2);
}
}
/**
* Parse the byte[] and fill keyStart, keyEnd.
*/
private void parse() {
parsed = true;
byte itemSeparator = oi.getItemSeparator();
byte keyValueSeparator = oi.getKeyValueSeparator();
boolean isEscaped = oi.isEscaped();
byte escapeChar = oi.getEscapeChar();
// empty array?
if (length == 0) {
mapSize = 0;
return;
}
mapSize = 0;
int arrayByteEnd = start + length;
int elementByteBegin = start;
int keyValueSeparatorPosition = -1;
int elementByteEnd = start;
byte[] bytes = this.bytes.getData();
Set