| Class | Description |
|---|---|
| AbstractTextConnection |
Base class for Text/CSV connections.
|
| ConsoleAdapters |
Pre Java SE 6 adapters for
System.in and System.out |
| Driver |
Represents a Text file driver.
|
| TextConnection |
Represents a connection to a Text file.
|
| TextConnectionParameters |
Connection parameters for text drivers.
|
| TextScriptExecutor |
Writes a text content to the output and performs properties expansion.
|
| Exception | Description |
|---|---|
| TextProviderException |
Thrown to indicate a problem with Text file processing.
|
Text driver does depends on additional libraries and is generally faster than CSV or Velocity driver.
Note: The driver doesn't use SQL syntax
| Driver class: | scriptella.driver.text.Driver |
| URL: | Text file URL. URIs are resolved relative to a script file directory.
If url has no value the output is read from/printed to the console (System.out). |
| Runtime dependencies: | None |
| Name | Description | Required |
|---|---|---|
| encoding | Specifies charset encoding of Text files. | No, the system default encoding is used. |
| eol | End-Of-Line suffix. Only valid for <script> elements. |
No, the default value is \n. |
| trim | Value of true specifies that the leading and trailing
whitespaces in text file lines should be omitted.
| No, the default value is true. |
| flush | Value of true specifies that the outputted content should flushed immediately when
the <script> element completes.
| No, the default value is false. |
| skip_lines | The number of lines to skip before start reading. | No, the default value is 0 (no lines are skipped). |
| null_string | Specifies string token to represent Java null literal.
When querying a text file, regex group equal to null_string is returned as Java null. Specify an empty string ( |
No, by default strings are preserved, i.e. empty strings are not converted to nulls and null variables references are not expanded in the output, i.e. ${nullvalue}. |
If a line or a part of it matches the pattern this match produces a virtual row in a result set.
The column names in a virtual result set correspond to matched regex group names.
For example query foo(.*) matches foobar line and the produced
result set row contains two columns(groups): 0-foobar, 1-bar. These columns
can be referenced in child script or query elements by a numeric name or by a string name columnN.
It also possible to specify more than one regular expressions to match file content. Specify each regular expression on a separate line to match them using OR condition.
The Text driver uses java.util.regex implementation for pattern matching. See java.util.Pattern
for supported syntax Javadoc.
Additional notes:
0(zero) column name in the produced result set contains the matched line.
<query>
^ERROR: (.*)
WARNING: (.*Failed.*)
([\d]+) errors?
</query>
This query consists of 3 regular expressions:
ERROR: prefixWARNING lines having Failed substring
Log file started...
INFO: INIT
WARNING: CPU is slow
WARNING: Failed to increase heap size
ERROR: Process interrupted
Operation completed with 1 error.
As the result of query execution the following set of rows is produced:
| 0 | 1 |
|---|---|
| WARNING: Failed to increase heap size | Failed to increase heap size |
| ERROR: Process interrupted | Process interrupted |
| 1 error | 1 |
Additional notes:
eol connection property.
<script>
Inserted a record with ID=$id. Table=${table}
</script>
For id=1 and table=system this script produces the following output:
Inserted a record with ID=1. Table=system
NOTE:
By default NULL variables and expressions are preserved, usenull_string connection property to specify
a string token for nulls.
For example setting null_string to empty string in the connection properties section will enable parsing
empty strings as nulls:
<connection driver="csv" url="report.csv">
null_string=
</connection>
Scriptella properties substitution engine cannot distinguish null value from unused variable or some random usage of
$var syntax,
therefore we've chosen to preserve these blocks until user explicitly specify the value of null_string.
<connection id="in" driver="text" url="data.csv">
</connection>
<connection id="out" driver="text" url="report.csv">
</connection>
<script connection-id="out">
ID;Priority;Summary;Status
</script>
<query connection-id="in">
<script connection-id="out">
$rownum;$column0;$column1;$column2
</script>
</query>
Copies rows from data.csv file to report.csv, additionally the ID column is added.
The result file is semicolon separated.
format.someColumn.type=number format.someColumn.pattern=000.00
Each property has the following formatting/parsing options (see PropertyFormat class for implementation details):
| Type(s) | Patterns |
|---|---|
| number | Decimal format pattern, e.g. ###,###.## or #.00 |
| date time |
date/time pattern, e.g. yyyy-MM-dd'T'HH:mm:ss.SSSZ |
| timestamp | JDBC timestamp escape format pattern - yyyy-mm-dd hh:mm:ss.fffffffff, where ffffffffff indicates nanoseconds. |
| choice | Choice-format pattern, e.g. 0#no files|1#{0} file|2<{0} files, . |
Copyright © Copyright 2006-2019 The Scriptella Project Team.