The DBToaster compiler can generate C++ or Scala code in two different forms:
- Standalone Binary - Generating a binary that incrementally evaluates a given SQL query requires invoking a second stage compiler (g++ or scalac).
- Source Code - Generated code can be easily embedded into user applications.
1. Evaluating a simple queryDBToaster provides the -r flag that generates, compiles, and runs the generated program in one simple step. This is a convenient way to check whether DBToaster and its dependencies have been successfully installed.
The following command evaluates the rst query on the toy dataset that ships with DBToaster:
2. Generating Standalone Binaries
Invoke DBToaster with -c [binary name] to create a standalone binary. By default, the compiler uses the C++ backend to produce an executable binary. Once invoked, the program prints out the results of all the queries contained in the input file after processing the whole input data.
The following command uses the C++ backend to generate the rst executable:
Running the rst executable produces the following output:
To produce a Scala jar file, invoke DBToaster with -l scala and the -c [binary name] flag as above. DBToaster will produce [binary name].jar, which can be run as a normal Scala program. For more details, please refer to Scala Code Generation.
3. Generating Source Code
DBToaster's primary role is to generate code that can be embedded into user applications. To produce a source file in C++ or Scala, invoke the compiler with -l [language], replacing [language] with cpp or scala. If the optional -o flag is used to redirect the generated code into a file, the target language will be auto-detected from the file suffix (".scala" for Scala and ".h", ".hpp", or ".cpp" for C++).