What objects/functions are available for custom data extractors?

From looking at the included custom data extractors (e.g. HTML-JavaScript.html.js), I can see that the objects/variables TRANSPOSED, COLUMNS, ROWS and FORMATTER are available.

Is there any documentation on these objects?
What methods are available on them?
Are there other objects that are available?

11 comments
Comment actions Permalink

Hi Vidar!

This API is experimental, it is not published yet, and it is subject to change.

But here is some overview on what there is:

Binding Type Description
 
DIALECT
com.intellij.database.dialects.DatabaseDialect  
Database dialect
 
TABLE
com.intellij.database.model.DasTable Database table metadata
 
ALL_COLUMNS
java.util.List<? extends com.intellij.database.extractors.DataColumn>  
A list of all columns in query result/currently open table editor.
com.intellij.database.extractors.DataColumn exposes
 
int columnNumber();
String name();
 
COLUMNS
java.util.List<? extends com.intellij.database.extractors.DataColumn>  
A list of selected columns in query result/currently open table editor.
 
FORMATTER
com.intellij.database.extractors.ValueFormatter

Exposes default formatting methods:
java.lang.String format(com.intellij.database.extractors.DataRow, com.intellij.database.extractors.DataColumn);
java.lang.String format(java.lang.Object, com.intellij.database.extractors.DataColumn);

OUT java.lang.Appendable Extractor output
ROWS java.lang.Iterable<com.intellij.database.extractors.DataRow>

Row data stream.
com.intellij.database.extractors.DataRow exposes:

 
int rowNumber();
boolean first
();
boolean last
();
java.util.List<java.lang.Object> data();
Object value(com.intellij.database.extractors.DataColumn);
TRANSPOSED java.lang.Boolean Indicates whether the table editor is in transposed mode.


I hope, it helps. Feel free to ask questions and share your ideas on how to improve this feature.

3
Comment actions Permalink

Great, thanks!

Is the source code or API of those com.intellij.database.* classes (like com.intellij.database.model.DasTable) available somewhere?

0
Comment actions Permalink

Not yet, but they will become a part of public API, too.

Until then, if you need help figuring out something - just ask, and we'll try to help you.

BTW, what kind of extractor are you trying to build?

0
Comment actions Permalink

Currently I'm building an extractor that will provide data for our DB test runner, on the form

<TABLENAME COLUMN1="column1value" COLUMN2="column2value"/>

- which I just now succeeded in doing, thanks to TABLE.name. Thanks!

Previously I wrote an extractor that outputs the resultset in JIRA markup table format:

|| COLUMN1 || COLUMN2 ||
|  R1C1 | R1C2 |
|  R2C1 | R2C2|


I'll post the code for the JIRA extractor here, in case it can help anyone:

var NEWLINE = "\n";

function output() {
  for (var i = 0; i < arguments.length; i++) {
    OUT.append(arguments[i]);
  }
}

var headerIterator = COLUMNS.iterator();
while (headerIterator.hasNext()) {
  var col = headerIterator.next();
  output("||");
  output(col.name());
}
output("||");

var rowIterator = ROWS.iterator();
while (rowIterator.hasNext()) {
  var row = rowIterator.next();
  output(NEWLINE);
  var columnIterator = COLUMNS.iterator();
  while (columnIterator.hasNext()) {
    var column = columnIterator.next();
    output("|");
    output(FORMATTER.format(row, column));
  }
  output("|");
}


Date formatting will probably be an issue soon.

Where does FORMATTER get its date format from, when formatting an Oracle DATE value, for example?

0
Comment actions Permalink

For now, it doesn't do anything clever - it just uses "yyyy-MM-dd HH:mm:ss" for timestamps, "yyyy-MM-dd" for dates, and "HH:mm:ss" for times.

So you may want to use the instanceof operator to dispatch on value types and format them the way you want.

0
Comment actions Permalink

Good news!

Starting with the 1.0 Public Preview build, we're shipping sources for open API parts of the product.

They can be found in %IDE_HOME%/lib/src/src_database-openapi.zip.

Happy hacking!

1
Comment actions Permalink

Woohooo! :)

0
Comment actions Permalink

If anyone is interested: I've written a MySQL like output format the other day. For small datasets it makes it easy to communicate the values using fixed width font:

+-------+-----------------+---------------------+
| sapID | fulfilment_type | start_time          |
+-------+-----------------+---------------------+
| 3595  | COLLECTION      | 1970-01-05 08:00:00 |
| 3595  | COLLECTION      | 1970-01-05 10:00:00 |
| 3595  | COLLECTION      | 1970-01-05 12:00:00 |
| 3595  | COLLECTION      | 1970-01-05 14:00:00 |
| 3595  | COLLECTION      | 1970-01-05 16:00:00 |
+-------+-----------------+---------------------+
5 rows in set.

You can find it here https://github.com/aukevanleeuwen/intellij-extractors 

0
Comment actions Permalink

@Sergey Savenko thanks, but how to import the package?

i use

import com.intellij.database.model.DasTable

but it

0
Comment actions Permalink

Unfortunately, %IDE_HOME%/lib/src/src_database-openapi.zip was included in datagrip-2016.1.exe, but is missing in datagrip-2016.3.2.exe and later versions.

And com.intellij.database java sources aren't still published in any googlable place.

0
Comment actions Permalink

When highlighting a sql select statement and using the execute to file/SQL Inserts method, the TABLE object supplied to the extractors is null and all insert statements are using "MY_TABLE" as the table name. 

INSERT INTO "MY_TABLE"( ...
INSERT INTO "MY_TABLE"( ...
INSERT INTO "MY_TABLE"( ...
...

 

However, when executing the same statement without export, then exporting from the results pane, the table object gets supplied to the sql inserts script and the insert statements are using the correct table name.  

insert into report.product( ...
insert into report.product( ...
insert into report.product( ...
...

 

Is there a way to get the table name for an extractor when executing to file?

I also notice that when using the same export/extractor method (SQL Inserts), the sql statement case when using the method from the results pane (lower) is different from when applied directly to a sql statement.   I feel like this is a clue, but I don't know where to go from here.  Thanks!

 

 

0

Please sign in to leave a comment.