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.pig.data;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import org.apache.pig.backend.executionengine.ExecException;
import org.apache.pig.classification.InterfaceAudience;
import org.apache.pig.classification.InterfaceStability;
import org.apache.pig.data.utils.SedesHelper;
@InterfaceAudience.Public
@InterfaceStability.Unstable
public abstract class AppendableSchemaTuple> extends SchemaTuple {
private static final long serialVersionUID = 1L;
private Tuple appendedFields;
private static final TupleFactory mTupleFactory = TupleFactory.getInstance();
@Override
public void append(Object val) {
if (appendedFields == null) {
appendedFields = mTupleFactory.newTuple();
}
appendedFields.append(val);
}
protected int appendedFieldsSize() {
return appendedFields == null ? 0 : appendedFields.size();
}
protected boolean isAppendedFieldsNull() {
return appendedFieldsSize() == 0;
}
protected Object getAppendedField(int i) throws ExecException {
return isAppendedFieldNull(i) ? null : appendedFields.get(i);
}
private boolean isAppendedFieldNull(int i) throws ExecException {
return isAppendedFieldsNull() || appendedFields.isNull(i);
}
public Tuple getAppendedFields() {
return appendedFields;
}
protected void setAppendedFields(Tuple t) {
appendedFields = t;
}
private void resetAppendedFields() {
appendedFields = null;
}
private void setAppendedField(int fieldNum, Object val) throws ExecException {
appendedFields.set(fieldNum, val);
}
/**
* This adds the additional overhead of the append Tuple
*/
@Override
public long getMemorySize() {
return SizeUtil.roundToEight(appendedFields.getMemorySize()) + super.getMemorySize();
}
private byte getAppendedFieldType(int i) throws ExecException {
return appendedFields == null ? DataType.UNKNOWN : appendedFields.getType(i);
}
protected SchemaTuple set(SchemaTuple> t, boolean checkType) throws ExecException {
resetAppendedFields();
for (int j = schemaSize(); j < t.size(); j++) {
append(t.get(j));
}
return super.set(t, checkType);
}
protected SchemaTuple setSpecific(T t) {
resetAppendedFields();
setAppendedFields(t.getAppendedFields());
return super.setSpecific(t);
}
public SchemaTuple set(List