/** Copy the current object contents into the output. Only copy selected entries, * as indicated by selectedInUse and the sel array. */ public void copySelected( bool selectedInUse, int[] sel, int size, BytesColumnVector output) { // Output has nulls if and only if input has nulls. output.noNulls = noNulls; output.isRepeating = false; // Handle repeating case if (isRepeating) { output.setVal(0, vector[0], start[0], length[0]); output.isNull[0] = isNull[0]; output.isRepeating = true; return; } // Handle normal case // Copy data values over if (selectedInUse) { for (int j = 0; j < size; j++) { int i = sel[j]; output.setVal(i, vector[i], start[i], length[i]); } } else { for (int i = 0; i < size; i++) { output.setVal(i, vector[i], start[i], length[i]); } } // Copy nulls over if needed if (!noNulls) { if (selectedInUse) { for (int j = 0; j < size; j++) { int i = sel[j]; output.isNull[i] = isNull[i]; } } else { Array.Copy(isNull, 0, output.isNull, 0, size); } } }
public override void setElement(int outElementNum, int inputElementNum, ColumnVector inputVector) { if (inputVector.isRepeating) { inputElementNum = 0; } if (inputVector.noNulls || !inputVector.isNull[inputElementNum]) { isNull[outElementNum] = false; BytesColumnVector @in = (BytesColumnVector)inputVector; setVal(outElementNum, @in.vector[inputElementNum], @in.start[inputElementNum], @in.length[inputElementNum]); } else { isNull[outElementNum] = true; noNulls = false; } }
private static string makeString(BytesColumnVector vector, int row) { if (vector.isRepeating) { row = 0; } if (vector.noNulls || !vector.isNull[row]) { return Encoding.UTF8.GetString(vector.vector[row], vector.start[row], vector.length[row]); } else { return null; } }
/* * Truncate a slice of a byte array to a maximum number of characters and * place the result into element i of a vector. */ public static void truncate(BytesColumnVector outV, int i, byte[] bytes, int start, int length, int maxLength) { int end = start + length; // count characters forward int j = start; int charCount = 0; while (j < end) { // UTF-8 continuation bytes have 2 high bits equal to 0x80. if ((bytes[j] & 0xc0) != 0x80) { if (charCount == maxLength) { break; } ++charCount; } j++; } // set output vector outV.setVal(i, bytes, start, (j - start)); }
// A setVal with the same function signature as rightTrim, leftTrim, truncate, etc, below. // Useful for class generation via templates. public static void assign(BytesColumnVector outV, int i, byte[] bytes, int start, int length) { // set output vector outV.setVal(i, bytes, start, length); }
/* * Right trim and truncate a slice of a byte array to a maximum number of characters and * place the result into element i of a vector. */ public static void rightTrimAndTruncate(BytesColumnVector outV, int i, byte[] bytes, int start, int length, int maxLength) { int end = start + length; // count characters forward and watch for final run of pads int j = start; int charCount = 0; int padRunStart = -1; while (j < end) { // UTF-8 continuation bytes have 2 high bits equal to 0x80. if ((bytes[j] & 0xc0) != 0x80) { if (charCount == maxLength) { break; } if (bytes[j] == 0x20) { if (padRunStart == -1) { padRunStart = j; } } else { padRunStart = -1; } ++charCount; } else { padRunStart = -1; } j++; } // set output vector if (padRunStart != -1) { outV.setVal(i, bytes, start, (padRunStart - start)); } else { outV.setVal(i, bytes, start, (j - start)); } }
/* * Right trim a slice of a byte array and place the result into element i of a vector. */ public static void rightTrim(BytesColumnVector outV, int i, byte[] bytes, int start, int length) { // skip trailing blank characters int j = start + length - 1; while (j >= start && bytes[j] == 0x20) { j--; } // set output vector outV.setVal(i, bytes, start, (j - start) + 1); }