Tue Sep 22, 2020 1:38 pm
Login Register Lost Password? Contact Us


Purpose of "Export Main" in Module structure

Comments and questions related to the Enterprise Control Language

Wed Jul 22, 2020 9:27 pm Change Time Zone

Hello,

I am trying to find out more about the "EXPORT MAIN" feature in a MODULE structure. Looking through the ECL documentation, I cannot find information about this and I am wondering if anyone has more details on why it exists, and what is the intended purpose.

All I know is that it can be used to test, or run a default outcome on a module. For example:

Code: Select all
EXPORT myModule := MODULE
  EXPORT add(integer4 aVar, integer4 bVar):= aVar + bVar;
  EXPORT MAIN := add(5,6);
END;

//myModule.add(1,3);
//myModule.MAIN;


If you save the module code as an independent attribute ( "myModele.ecl"), then submitting the "myModule" attribute directly to the HPCC cluster will result in the MAIN function being invoked. Meaning, that if you add code to test the module in the "MAIN" export then you can easily run a unit test on the module using some default values, or invoke some default behavior.

I did see some comments that it relates to queries, but I am not understanding how this fits into the HPCC run/deployment life cycle.

Please can someone point me to the documentation on this, or help me understand the purpose and correct usage.

Thank you.

Gabriel
gmarcan
 
Posts: 11
Joined: Wed Jul 30, 2014 3:44 pm

Thu Jul 23, 2020 12:16 pm Change Time Zone

Gabriel,

You have discovered a kludge that allows you to exercise a "bad habit" to get into.

In every class I teach, I tell the students: "Don't get into the habit of just hitting Submit on definition files, because sometimes it will work and sometimes it won't! You should only hit the Submit button on BWR files (Builder Window Runnable -- ECL code files that contain actions, not just definitions)."

A MODULE structure definition file is one of those where it won't work, and produces an error that says, "Module yourfilename does not EXPORT an attribute main()" because there is no action to execute in the file, just the MODULE definition.

So, by adding an "EXPORT Main" definition within the MODULE you can get away with just hitting Submit, because the compiler takes that definition as the missing "main()" that it's looking for and uses that as the action to execute. And that is a bad habit to get into! :)

HTH,

Richard
rtaylor
Community Advisory Board Member
Community Advisory Board Member
 
Posts: 1554
Joined: Wed Oct 26, 2011 7:40 pm

Fri Jul 24, 2020 6:03 pm Change Time Zone

Hi Richard,

Thank you. Do you know what is the intended purpose of "EXPORT MAIN"? Is it just a quirk that some how relates to the underlying compiler?

I did manage to find another reference out there to the "EXPORT MAIN", but it does not provide much further insight:

viewtopic.php?f=8&t=125

Nonetheless, I find your advise sensible and I will avoid using this construct for creating unit testing. The use of #IF along with a constant configuration attribute provides a much more consistent and elegant option.

Gabriel
gmarcan
 
Posts: 11
Joined: Wed Jul 30, 2014 3:44 pm

Fri Jul 24, 2020 6:33 pm Change Time Zone

Gabriel,
Is it just a quirk that some how relates to the underlying compiler?
Pretty much. ECL defines what you want, the compiler generates the code for how to do it. And that generated code is C++,and all C/C++ programs need to have a main() to compile.

HTH,

Richard
rtaylor
Community Advisory Board Member
Community Advisory Board Member
 
Posts: 1554
Joined: Wed Oct 26, 2011 7:40 pm

Fri Jul 24, 2020 6:52 pm Change Time Zone

Hi Richard,

This answers my question.

Thank you.

Gabriel
gmarcan
 
Posts: 11
Joined: Wed Jul 30, 2014 3:44 pm


Return to ECL

Who is online

Users browsing this forum: No registered users and 1 guest