private int[] readMetadata(ByteArrayInputStream inputStream, byte[] columnTypes) throws IOException { int[] metadata = new int[columnTypes.length]; for (int i = 0; i < columnTypes.length; i++) { switch (ColumnType.byCode(columnTypes[i] & 0xFF)) { case FLOAT: case DOUBLE: case BLOB: case JSON: case GEOMETRY: metadata[i] = inputStream.readInteger(1); break; case BIT: case VARCHAR: case NEWDECIMAL: metadata[i] = inputStream.readInteger(2); break; case SET: case ENUM: case STRING: metadata[i] = bigEndianInteger(inputStream.read(2), 0, 2); break; case TIME_V2: case DATETIME_V2: case TIMESTAMP_V2: metadata[i] = inputStream.readInteger(1); // fsp (@see {@link ColumnType}) break; default: metadata[i] = 0; } } return metadata; }
// Returns the resolved symbol in the binary. The BE will do a lookup of 'symbol' // in the binary and try to resolve unmangled names. // If this function is expecting a return argument, retArgType is that type. It should // be null if this function isn't expecting a return argument. protected String lookupSymbol( String symbol, ColumnType retArgType, boolean hasVarArgs, ColumnType... argTypes) throws AnalysisException { if (symbol.length() == 0) { throw new AnalysisException( "Could not find symbol '' in: " + fn_.getLocation().getLocation()); } if (fn_.getBinaryType() == TFunctionBinaryType.HIVE) { // TODO: add this when hive udfs go in. return symbol; } Preconditions.checkState( fn_.getBinaryType() == TFunctionBinaryType.NATIVE || fn_.getBinaryType() == TFunctionBinaryType.IR); TSymbolLookupParams lookup = new TSymbolLookupParams(); lookup.location = fn_.getLocation().toString(); lookup.symbol = symbol; lookup.fn_binary_type = fn_.getBinaryType(); lookup.arg_types = ColumnType.toThrift(argTypes); lookup.has_var_args = hasVarArgs; if (retArgType != null) lookup.setRet_arg_type(retArgType.toThrift()); try { TSymbolLookupResult result = FeSupport.LookupSymbol(lookup); switch (result.result_code) { case SYMBOL_FOUND: return result.symbol; case BINARY_NOT_FOUND: throw new AnalysisException( "Could not load binary: " + fn_.getLocation().getLocation() + "\n" + result.error_msg); case SYMBOL_NOT_FOUND: throw new AnalysisException(result.error_msg); default: // Should never get here. throw new AnalysisException("Internal Error"); } } catch (InternalException e) { throw new AnalysisException("Could not find symbol.", e); } }
public void visit(ColumnType entity) { wGetVisitor1().visit(entity.getType()); wGetVisitor1().visit(entity.getSize()); wGetVisitor1().visit(entity.getPrecision()); }
@Test public void lookup_for_supported_column_type() { ColumnType type = ColumnType.fromValue(1); assertThat(type, is(notNullValue())); assertThat(type, is(ColumnType.NUMBER)); }
@Test public void verify_only_four_column_types_supported() { assertThat(ColumnType.values().length, is(4)); }