Adds the user defined function fn to metastore DB params. fn is serialized to thrift using TBinaryProtocol and then base64-encoded to be compatible with the HMS' representation of params.
(Function fn)
| 339 | * to be compatible with the HMS' representation of params. |
| 340 | */ |
| 341 | private boolean addFunctionToDbParams(Function fn) { |
| 342 | Preconditions.checkState( |
| 343 | fn.getBinaryType() != TFunctionBinaryType.BUILTIN && |
| 344 | fn.getBinaryType() != TFunctionBinaryType.JAVA); |
| 345 | try { |
| 346 | TSerializer serializer = |
| 347 | new TSerializer(new TCompactProtocol.Factory()); |
| 348 | byte[] serializedFn = serializer.serialize(fn.toThrift()); |
| 349 | String base64Fn = Base64.getEncoder().encodeToString(serializedFn); |
| 350 | String fnKey = FUNCTION_INDEX_PREFIX + fn.signatureString(); |
| 351 | if (base64Fn.length() > HIVE_METASTORE_DB_PARAM_LIMIT_BYTES) { |
| 352 | throw new ImpalaRuntimeException( |
| 353 | "Serialized function size exceeded HMS 4K byte limit"); |
| 354 | } |
| 355 | putToHmsParameters(fnKey, base64Fn); |
| 356 | } catch (ImpalaException | TException e) { |
| 357 | LOG.error("Error adding function " + fn.getName() + " to DB params", e); |
| 358 | return false; |
| 359 | } |
| 360 | return true; |
| 361 | } |
| 362 | |
| 363 | public boolean addFunction(Function fn) { |
| 364 | // We use the db parameters map to persist native and IR functions. |
no test coverage detected