Просмотр исходного кода

HPCC-24604 Standard Library support for generating a Globally Unique ID

Signed-off-by: Anthony Fishbeck <anthony.fishbeck@lexisnexisrisk.com>
Anthony Fishbeck 4 лет назад
Родитель
Сommit
1bc94578cb

+ 7 - 0
ecllibrary/std/system/Log.ecl

@@ -73,5 +73,12 @@ EXPORT getCallerId() := lib_logging.Logging.getCallerId();
 
 EXPORT getLocalId() := lib_logging.Logging.getLocalId();
 
+/*
+ * Generate a globally unique Id with base58 encoding.
+ *
+ * Returns the unique Id
+ */
+
+EXPORT generateGloballyUniqueId() := lib_logging.Logging.generateGloballyUniqueId();
 
 END;

+ 8 - 0
plugins/logging/logging.cpp

@@ -40,6 +40,7 @@ static const char * EclDefinition =
 "  varstring getGlobalId() : c,context,entrypoint='logGetGlobalId'; \n"
 "  varstring getLocalId() : c,context,entrypoint='logGetLocalId'; \n"
 "  varstring getCallerId() : c,context,entrypoint='logGetCallerId'; \n"
+"  varstring generateGloballyUniqueId() : c,entrypoint='logGenerateGloballyUniqueId'; \n"
 "END;";
 
 LOGGING_API bool getECLPluginDefinition(ECLPluginDefinitionBlock *pb) 
@@ -91,3 +92,10 @@ LOGGING_API char *  LOGGING_CALL logGetCallerId(ICodeContext *ctx)
     StringBuffer ret(ctx->queryContextLogger().queryCallerId());
     return ret.detach();
 }
+
+LOGGING_API char * LOGGING_CALL logGenerateGloballyUniqueId()
+{
+    StringBuffer ret;
+    appendGloballyUniqueId(ret);
+    return ret.detach();
+}

+ 2 - 0
plugins/logging/logging.hpp

@@ -39,6 +39,8 @@ LOGGING_API void LOGGING_CALL logDbgLog(unsigned srcLen, const char * src);
 LOGGING_API char * LOGGING_CALL logGetGlobalId(ICodeContext *ctx);
 LOGGING_API char * LOGGING_CALL logGetCallerId(ICodeContext *ctx);
 LOGGING_API char * LOGGING_CALL logGetLocalId(ICodeContext *ctx);
+LOGGING_API char * LOGGING_CALL logGenerateGloballyUniqueId();
+
 }
 
 #endif

+ 3 - 0
testing/regress/ecl/key/uniqueid.xml

@@ -0,0 +1,3 @@
+<Dataset name='Result 1'>
+ <Row><Result_1>values are unique</Result_1></Row>
+</Dataset>

+ 23 - 0
testing/regress/ecl/uniqueid.ecl

@@ -0,0 +1,23 @@
+/*##############################################################################
+
+    HPCC SYSTEMS software Copyright (C) 2020 HPCC Systems®.
+
+    Licensed 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.
+############################################################################## */
+
+IMPORT STD;
+
+value1 := std.system.log.generateGloballyUniqueId() : independent;
+value2 := std.system.log.generateGloballyUniqueId() + NOFOLD('') : independent;
+
+output(if (value1 = value2, 'values are not unique', 'values are unique'));