use of org.apache.hadoop.hive.ql.exec.vector.LongColumnVector in project hive by apache.
the class VectorElt method evaluate.
@Override
public void evaluate(VectorizedRowBatch batch) {
if (childExpressions != null) {
super.evaluateChildren(batch);
}
int[] sel = batch.selected;
int n = batch.size;
BytesColumnVector outputVector = (BytesColumnVector) batch.cols[outputColumnNum];
if (n <= 0) {
return;
}
outputVector.init();
outputVector.noNulls = false;
outputVector.isRepeating = false;
LongColumnVector inputIndexVector = (LongColumnVector) batch.cols[inputColumns[0]];
long[] indexVector = inputIndexVector.vector;
if (inputIndexVector.isRepeating) {
int index = (int) indexVector[0];
if (index > 0 && index < inputColumns.length) {
BytesColumnVector cv = (BytesColumnVector) batch.cols[inputColumns[index]];
if (cv.isRepeating) {
outputVector.setElement(0, 0, cv);
outputVector.isRepeating = true;
} else if (batch.selectedInUse) {
for (int j = 0; j != n; j++) {
int i = sel[j];
outputVector.setVal(i, cv.vector[0], cv.start[0], cv.length[0]);
}
} else {
for (int i = 0; i != n; i++) {
outputVector.setVal(i, cv.vector[0], cv.start[0], cv.length[0]);
}
}
} else {
outputVector.isNull[0] = true;
outputVector.isRepeating = true;
}
} else if (batch.selectedInUse) {
for (int j = 0; j != n; j++) {
int i = sel[j];
int index = (int) indexVector[i];
if (index > 0 && index < inputColumns.length) {
BytesColumnVector cv = (BytesColumnVector) batch.cols[inputColumns[index]];
int cvi = cv.isRepeating ? 0 : i;
outputVector.setVal(i, cv.vector[cvi], cv.start[cvi], cv.length[cvi]);
} else {
outputVector.isNull[i] = true;
}
}
} else {
for (int i = 0; i != n; i++) {
int index = (int) indexVector[i];
if (index > 0 && index < inputColumns.length) {
BytesColumnVector cv = (BytesColumnVector) batch.cols[inputColumns[index]];
int cvi = cv.isRepeating ? 0 : i;
outputVector.setVal(i, cv.vector[cvi], cv.start[cvi], cv.length[cvi]);
} else {
outputVector.isNull[i] = true;
}
}
}
}
use of org.apache.hadoop.hive.ql.exec.vector.LongColumnVector in project hive by apache.
the class VectorUDFDateAddScalarCol method evaluate.
@Override
public void evaluate(VectorizedRowBatch batch) {
if (childExpressions != null) {
super.evaluateChildren(batch);
}
LongColumnVector inputCol = (LongColumnVector) batch.cols[this.colNum];
/* every line below this is identical for evaluateLong & evaluateString */
final int n = inputCol.isRepeating ? 1 : batch.size;
int[] sel = batch.selected;
final boolean selectedInUse = (inputCol.isRepeating == false) && batch.selectedInUse;
LongColumnVector outputColVector = (LongColumnVector) batch.cols[outputColumnNum];
boolean[] outputIsNull = outputColVector.isNull;
switch(primitiveCategory) {
case DATE:
baseDate.setTime(DateWritable.daysToMillis((int) longValue));
break;
case TIMESTAMP:
baseDate.setTime(timestampValue.getTime());
break;
case STRING:
case CHAR:
case VARCHAR:
boolean parsed = dateParser.parseDate(new String(stringValue, StandardCharsets.UTF_8), baseDate);
if (!parsed) {
outputColVector.noNulls = false;
if (selectedInUse) {
for (int j = 0; j < n; j++) {
int i = sel[j];
outputColVector.isNull[i] = true;
}
} else {
for (int i = 0; i < n; i++) {
outputColVector.isNull[i] = true;
}
}
return;
}
break;
default:
throw new Error("Unsupported input type " + primitiveCategory.name());
}
if (batch.size == 0) {
/* n != batch.size when isRepeating */
return;
}
// We do not need to do a column reset since we are carefully changing the output.
outputColVector.isRepeating = false;
long baseDateDays = DateWritable.millisToDays(baseDate.getTime());
if (inputCol.isRepeating) {
if (inputCol.noNulls || !inputCol.isNull[0]) {
outputColVector.isNull[0] = false;
evaluate(baseDateDays, inputCol.vector[0], outputColVector, 0);
} else {
outputColVector.isNull[0] = true;
outputColVector.noNulls = false;
}
outputColVector.isRepeating = true;
return;
}
if (inputCol.noNulls) {
if (batch.selectedInUse) {
if (!outputColVector.noNulls) {
for (int j = 0; j != n; j++) {
final int i = sel[j];
// Set isNull before call in case it changes it mind.
outputIsNull[i] = false;
evaluate(baseDateDays, inputCol.vector[i], outputColVector, i);
}
} else {
for (int j = 0; j != n; j++) {
final int i = sel[j];
evaluate(baseDateDays, inputCol.vector[i], outputColVector, i);
}
}
} else {
if (!outputColVector.noNulls) {
// Assume it is almost always a performance win to fill all of isNull so we can
// safely reset noNulls.
Arrays.fill(outputIsNull, false);
outputColVector.noNulls = true;
}
for (int i = 0; i != n; i++) {
evaluate(baseDateDays, inputCol.vector[i], outputColVector, i);
}
}
} else /* there are nulls in the inputColVector */
{
// Carefully handle NULLs..
// Handle case with nulls. Don't do function if the value is null, to save time,
// because calling the function can be expensive.
outputColVector.noNulls = false;
if (selectedInUse) {
for (int j = 0; j < n; j++) {
int i = sel[j];
outputColVector.isNull[i] = inputCol.isNull[i];
if (!inputCol.isNull[i]) {
evaluate(baseDateDays, inputCol.vector[i], outputColVector, i);
}
}
} else {
for (int i = 0; i < n; i++) {
outputColVector.isNull[i] = inputCol.isNull[i];
if (!inputCol.isNull[i]) {
evaluate(baseDateDays, inputCol.vector[i], outputColVector, i);
}
}
}
}
}
use of org.apache.hadoop.hive.ql.exec.vector.LongColumnVector in project hive by apache.
the class VectorUDFDateDiffColScalar method evaluate.
@Override
public void evaluate(VectorizedRowBatch batch) {
if (childExpressions != null) {
super.evaluateChildren(batch);
}
LongColumnVector outputColVector = (LongColumnVector) batch.cols[outputColumnNum];
ColumnVector inputCol = batch.cols[this.colNum];
/* every line below this is identical for evaluateLong & evaluateString */
final int n = inputCol.isRepeating ? 1 : batch.size;
int[] sel = batch.selected;
final boolean selectedInUse = (inputCol.isRepeating == false) && batch.selectedInUse;
boolean[] outputIsNull = outputColVector.isNull;
if (batch.size == 0) {
/* n != batch.size when isRepeating */
return;
}
// We do not need to do a column reset since we are carefully changing the output.
outputColVector.isRepeating = false;
PrimitiveCategory primitiveCategory1 = ((PrimitiveTypeInfo) inputTypeInfos[1]).getPrimitiveCategory();
switch(primitiveCategory1) {
case DATE:
baseDate = (int) longValue;
break;
case TIMESTAMP:
date.setTime(timestampValue.getTime());
baseDate = DateWritable.dateToDays(date);
break;
case STRING:
case CHAR:
case VARCHAR:
try {
date.setTime(formatter.parse(new String(bytesValue, "UTF-8")).getTime());
baseDate = DateWritable.dateToDays(date);
break;
} catch (Exception e) {
outputColVector.noNulls = false;
if (selectedInUse) {
for (int j = 0; j < n; j++) {
int i = sel[j];
outputColVector.isNull[i] = true;
}
} else {
for (int i = 0; i < n; i++) {
outputColVector.isNull[i] = true;
}
}
return;
}
default:
throw new Error("Invalid input type #1: " + primitiveCategory1.name());
}
PrimitiveCategory primitiveCategory0 = ((PrimitiveTypeInfo) inputTypeInfos[0]).getPrimitiveCategory();
switch(primitiveCategory0) {
case DATE:
if (inputCol.isRepeating) {
if (inputCol.noNulls || !inputCol.isNull[0]) {
outputColVector.isNull[0] = false;
outputColVector.vector[0] = evaluateDate(inputCol, 0);
} else {
outputColVector.isNull[0] = true;
outputColVector.noNulls = false;
}
outputColVector.isRepeating = true;
} else if (inputCol.noNulls) {
if (batch.selectedInUse) {
if (!outputColVector.noNulls) {
for (int j = 0; j != n; j++) {
final int i = sel[j];
// Set isNull before call in case it changes it mind.
outputIsNull[i] = false;
outputColVector.vector[i] = evaluateDate(inputCol, i);
}
} else {
for (int j = 0; j != n; j++) {
final int i = sel[j];
outputColVector.vector[i] = evaluateDate(inputCol, i);
}
}
} else {
if (!outputColVector.noNulls) {
// Assume it is almost always a performance win to fill all of isNull so we can
// safely reset noNulls.
Arrays.fill(outputIsNull, false);
outputColVector.noNulls = true;
}
for (int i = 0; i != n; i++) {
outputColVector.vector[i] = evaluateDate(inputCol, i);
}
}
} else /* there are nulls in the inputColVector */
{
// Carefully handle NULLs..
// Handle case with nulls. Don't do function if the value is null, to save time,
// because calling the function can be expensive.
outputColVector.noNulls = false;
if (selectedInUse) {
for (int j = 0; j < n; j++) {
int i = sel[j];
outputColVector.isNull[i] = inputCol.isNull[i];
if (!inputCol.isNull[i]) {
outputColVector.vector[i] = evaluateDate(inputCol, i);
}
}
} else {
for (int i = 0; i < n; i++) {
outputColVector.isNull[i] = inputCol.isNull[i];
if (!inputCol.isNull[i]) {
outputColVector.vector[i] = evaluateDate(inputCol, i);
}
}
}
}
break;
case TIMESTAMP:
if (inputCol.isRepeating) {
if (inputCol.noNulls || !inputCol.isNull[0]) {
outputColVector.isNull[0] = false;
outputColVector.vector[0] = evaluateTimestamp(inputCol, 0);
} else {
outputColVector.isNull[0] = true;
outputColVector.noNulls = false;
}
outputColVector.isRepeating = true;
} else if (inputCol.noNulls) {
if (batch.selectedInUse) {
if (!outputColVector.noNulls) {
for (int j = 0; j != n; j++) {
final int i = sel[j];
// Set isNull before call in case it changes it mind.
outputIsNull[i] = false;
outputColVector.vector[i] = evaluateTimestamp(inputCol, i);
}
} else {
for (int j = 0; j != n; j++) {
final int i = sel[j];
outputColVector.vector[i] = evaluateTimestamp(inputCol, i);
}
}
} else {
if (!outputColVector.noNulls) {
// Assume it is almost always a performance win to fill all of isNull so we can
// safely reset noNulls.
Arrays.fill(outputIsNull, false);
outputColVector.noNulls = true;
}
for (int i = 0; i != n; i++) {
outputColVector.vector[i] = evaluateTimestamp(inputCol, i);
}
}
} else /* there are nulls in the inputColVector */
{
// Carefully handle NULLs..
// Handle case with nulls. Don't do function if the value is null, to save time,
// because calling the function can be expensive.
outputColVector.noNulls = false;
if (selectedInUse) {
for (int j = 0; j < n; j++) {
int i = sel[j];
outputColVector.isNull[i] = inputCol.isNull[i];
if (!inputCol.isNull[i]) {
outputColVector.vector[i] = evaluateTimestamp(inputCol, i);
}
}
} else {
for (int i = 0; i < n; i++) {
outputColVector.isNull[i] = inputCol.isNull[i];
if (!inputCol.isNull[i]) {
outputColVector.vector[i] = evaluateTimestamp(inputCol, i);
}
}
}
}
break;
case STRING:
case CHAR:
case VARCHAR:
if (inputCol.isRepeating) {
if (inputCol.noNulls || !inputCol.isNull[0]) {
outputColVector.isNull[0] = false;
evaluateString(inputCol, outputColVector, 0);
} else {
outputColVector.isNull[0] = true;
outputColVector.noNulls = false;
}
outputColVector.isRepeating = true;
} else if (inputCol.noNulls) {
if (batch.selectedInUse) {
if (!outputColVector.noNulls) {
for (int j = 0; j != n; j++) {
final int i = sel[j];
// Set isNull before call in case it changes it mind.
outputIsNull[i] = false;
evaluateString(inputCol, outputColVector, i);
}
} else {
for (int j = 0; j != n; j++) {
final int i = sel[j];
evaluateString(inputCol, outputColVector, i);
}
}
} else {
if (!outputColVector.noNulls) {
// Assume it is almost always a performance win to fill all of isNull so we can
// safely reset noNulls.
Arrays.fill(outputIsNull, false);
outputColVector.noNulls = true;
}
for (int i = 0; i != n; i++) {
evaluateString(inputCol, outputColVector, i);
}
}
} else /* there are nulls in the inputColVector */
{
// Carefully handle NULLs..
// Handle case with nulls. Don't do function if the value is null, to save time,
// because calling the function can be expensive.
outputColVector.noNulls = false;
if (selectedInUse) {
for (int j = 0; j < n; j++) {
int i = sel[j];
outputColVector.isNull[i] = inputCol.isNull[i];
if (!inputCol.isNull[i]) {
evaluateString(inputCol, outputColVector, i);
}
}
} else {
for (int i = 0; i < n; i++) {
outputColVector.isNull[i] = inputCol.isNull[i];
if (!inputCol.isNull[i]) {
evaluateString(inputCol, outputColVector, i);
}
}
}
}
break;
default:
throw new Error("Invalid input type #0: " + primitiveCategory0.name());
}
}
use of org.apache.hadoop.hive.ql.exec.vector.LongColumnVector in project hive by apache.
the class VectorUDFTimestampFieldDate method evaluate.
@Override
public void evaluate(VectorizedRowBatch batch) {
Preconditions.checkState(((PrimitiveTypeInfo) inputTypeInfos[0]).getPrimitiveCategory() == PrimitiveCategory.DATE);
if (childExpressions != null) {
super.evaluateChildren(batch);
}
LongColumnVector outputColVector = (LongColumnVector) batch.cols[outputColumnNum];
ColumnVector inputColVec = batch.cols[this.colNum];
/* every line below this is identical for evaluateLong & evaluateString */
final int n = inputColVec.isRepeating ? 1 : batch.size;
int[] sel = batch.selected;
final boolean selectedInUse = (inputColVec.isRepeating == false) && batch.selectedInUse;
boolean[] outputIsNull = outputColVector.isNull;
if (batch.size == 0) {
/* n != batch.size when isRepeating */
return;
}
// We do not need to do a column reset since we are carefully changing the output.
outputColVector.isRepeating = false;
LongColumnVector longColVector = (LongColumnVector) inputColVec;
if (inputColVec.isRepeating) {
if (inputColVec.noNulls || !inputColVec.isNull[0]) {
outputColVector.isNull[0] = false;
outputColVector.vector[0] = getDateField(longColVector.vector[0]);
} else {
outputColVector.isNull[0] = true;
outputColVector.noNulls = false;
}
outputColVector.isRepeating = true;
return;
}
if (inputColVec.noNulls) {
if (batch.selectedInUse) {
if (!outputColVector.noNulls) {
for (int j = 0; j != n; j++) {
final int i = sel[j];
// Set isNull before call in case it changes it mind.
outputIsNull[i] = false;
outputColVector.vector[i] = getDateField(longColVector.vector[i]);
}
} else {
for (int j = 0; j != n; j++) {
final int i = sel[j];
outputColVector.vector[i] = getDateField(longColVector.vector[i]);
}
}
} else {
if (!outputColVector.noNulls) {
// Assume it is almost always a performance win to fill all of isNull so we can
// safely reset noNulls.
Arrays.fill(outputIsNull, false);
outputColVector.noNulls = true;
}
for (int i = 0; i != n; i++) {
outputColVector.vector[i] = getDateField(longColVector.vector[i]);
}
}
} else /* there are nulls in the inputColVector */
{
// Carefully handle NULLs...
outputColVector.noNulls = false;
if (selectedInUse) {
for (int j = 0; j < n; j++) {
int i = sel[j];
outputColVector.isNull[i] = inputColVec.isNull[i];
if (!inputColVec.isNull[i]) {
outputColVector.vector[i] = getDateField(longColVector.vector[i]);
}
}
} else {
for (int i = 0; i < n; i++) {
outputColVector.isNull[i] = inputColVec.isNull[i];
if (!inputColVec.isNull[i]) {
outputColVector.vector[i] = getDateField(longColVector.vector[i]);
}
}
}
}
}
use of org.apache.hadoop.hive.ql.exec.vector.LongColumnVector in project hive by apache.
the class VectorUDFTimestampFieldString method evaluate.
@Override
public void evaluate(VectorizedRowBatch batch) {
if (childExpressions != null) {
super.evaluateChildren(batch);
}
LongColumnVector outV = (LongColumnVector) batch.cols[outputColumnNum];
BytesColumnVector inputCol = (BytesColumnVector) batch.cols[this.colNum];
final int n = inputCol.isRepeating ? 1 : batch.size;
int[] sel = batch.selected;
final boolean selectedInUse = (inputCol.isRepeating == false) && batch.selectedInUse;
if (batch.size == 0) {
// n != batch.size when isRepeating
return;
}
// We do not need to do a column reset since we are carefully changing the output.
outV.isRepeating = false;
if (inputCol.isRepeating) {
if (inputCol.noNulls || !inputCol.isNull[0]) {
try {
outV.isNull[0] = false;
outV.vector[0] = getField(inputCol.vector[0], inputCol.start[0], inputCol.length[0]);
} catch (ParseException e) {
outV.noNulls = false;
outV.isNull[0] = true;
}
} else {
outV.isNull[0] = true;
outV.noNulls = false;
}
outV.isRepeating = true;
return;
}
if (inputCol.noNulls) {
if (selectedInUse) {
for (int j = 0; j < n; j++) {
int i = sel[j];
try {
outV.vector[i] = getField(inputCol.vector[i], inputCol.start[i], inputCol.length[i]);
outV.isNull[i] = false;
} catch (ParseException e) {
outV.noNulls = false;
outV.isNull[i] = true;
}
}
} else {
for (int i = 0; i < n; i++) {
try {
outV.vector[i] = getField(inputCol.vector[i], inputCol.start[i], inputCol.length[i]);
outV.isNull[i] = false;
} catch (ParseException e) {
outV.noNulls = false;
outV.isNull[i] = true;
}
}
}
} else /* there are nulls in the inputColVector */
{
// Carefully handle NULLs...
outV.noNulls = false;
if (selectedInUse) {
for (int j = 0; j < n; j++) {
int i = sel[j];
outV.isNull[i] = inputCol.isNull[i];
if (!inputCol.isNull[i]) {
try {
outV.vector[i] = getField(inputCol.vector[i], inputCol.start[i], inputCol.length[i]);
} catch (ParseException e) {
outV.isNull[i] = true;
}
}
}
} else {
for (int i = 0; i < n; i++) {
outV.isNull[i] = inputCol.isNull[i];
if (!inputCol.isNull[i]) {
try {
outV.vector[i] = getField(inputCol.vector[i], inputCol.start[i], inputCol.length[i]);
} catch (ParseException e) {
outV.isNull[i] = true;
}
}
}
}
}
}
Aggregations