use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteConnection in project beam by apache.
the class JdbcDriverTest method testInternalConnect_bounded_limit.
@Test
public void testInternalConnect_bounded_limit() throws Exception {
ReadOnlyTableProvider tableProvider = new ReadOnlyTableProvider("test", ImmutableMap.of("test", TestBoundedTable.of(Schema.FieldType.INT32, "id", Schema.FieldType.STRING, "name").addRows(1, "first").addRows(1, "second first").addRows(2, "second")));
CalciteConnection connection = JdbcDriver.connect(tableProvider, PipelineOptionsFactory.create());
Statement statement = connection.createStatement();
ResultSet resultSet1 = statement.executeQuery("SELECT * FROM test LIMIT 5");
assertTrue(resultSet1.next());
assertTrue(resultSet1.next());
assertTrue(resultSet1.next());
assertFalse(resultSet1.next());
assertFalse(resultSet1.next());
ResultSet resultSet2 = statement.executeQuery("SELECT * FROM test LIMIT 1");
assertTrue(resultSet2.next());
assertFalse(resultSet2.next());
ResultSet resultSet3 = statement.executeQuery("SELECT * FROM test LIMIT 2");
assertTrue(resultSet3.next());
assertTrue(resultSet3.next());
assertFalse(resultSet3.next());
ResultSet resultSet4 = statement.executeQuery("SELECT * FROM test LIMIT 3");
assertTrue(resultSet4.next());
assertTrue(resultSet4.next());
assertTrue(resultSet4.next());
assertFalse(resultSet4.next());
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteConnection in project beam by apache.
the class JdbcDriverTest method testInternalConnect_boundedTable.
@Test
public void testInternalConnect_boundedTable() throws Exception {
CalciteConnection connection = JdbcDriver.connect(BOUNDED_TABLE, PipelineOptionsFactory.create());
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT * FROM test");
assertTrue(resultSet.next());
assertEquals(1, resultSet.getInt("id"));
assertEquals("first", resultSet.getString("name"));
assertFalse(resultSet.next());
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteConnection in project apex-malhar by apache.
the class SQLExecEnvironment method withModel.
/**
* Use given model file to initialize {@link SQLExecEnvironment}.
* The model file contains definitions of endpoints and data formats.
* Example of file format is like following:
* <pre>
* {
* version: '1.0',
* defaultSchema: 'APEX',
* schemas: [{
* name: 'APEX',
* tables: [
* {
* name: 'ORDERS',
* type: 'custom',
* factory: 'org.apache.apex.malhar.sql.schema.ApexSQLTableFactory',
* stream: {
* stream: true
* },
* operand: {
* endpoint: 'file',
* messageFormat: 'csv',
* endpointOperands: {
* directory: '/tmp/input'
* },
* messageFormatOperands: {
* schema: '{"separator":",","quoteChar":"\\"","fields":[{"name":"RowTime","type":"Date","constraints":{"format":"dd/MM/yyyy hh:mm:ss"}},{"name":"id","type":"Integer"},{"name":"Product","type":"String"},{"name":"units","type":"Integer"}]}'
* }
* }
* }
* ]
* }]
* }
* </pre>
*
* @param model String content of model file.
* @return Returns this {@link SQLExecEnvironment}
*/
public SQLExecEnvironment withModel(String model) {
if (model == null) {
return this;
}
Properties p = new Properties();
p.put("model", "inline:" + model);
try (Connection connection = DriverManager.getConnection("jdbc:calcite:", p)) {
CalciteConnection conn = connection.unwrap(CalciteConnection.class);
this.schema = conn.getRootSchema().getSubSchema(connection.getSchema());
} catch (SQLException e) {
throw new RuntimeException(e);
}
return this;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteConnection in project lucene-solr by apache.
the class CalciteSolrDriver method connect.
@Override
public Connection connect(String url, Properties info) throws SQLException {
if (!this.acceptsURL(url)) {
return null;
}
Connection connection = super.connect(url, info);
CalciteConnection calciteConnection = (CalciteConnection) connection;
final SchemaPlus rootSchema = calciteConnection.getRootSchema();
String schemaName = info.getProperty("zk");
if (schemaName == null) {
throw new SQLException("zk must be set");
}
rootSchema.add(schemaName, new SolrSchema(info));
// Set the default schema
calciteConnection.setSchema(schemaName);
return connection;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteConnection in project nifi by apache.
the class QueryRecord method queryWithCache.
protected QueryResult queryWithCache(final ProcessSession session, final FlowFile flowFile, final String sql, final ProcessContext context, final RecordReaderFactory recordParserFactory) throws SQLException {
final Supplier<CalciteConnection> connectionSupplier = () -> {
final Properties properties = new Properties();
properties.put(CalciteConnectionProperty.LEX.camelName(), Lex.MYSQL_ANSI.name());
try {
final Connection connection = DriverManager.getConnection("jdbc:calcite:", properties);
final CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
return calciteConnection;
} catch (final Exception e) {
throw new ProcessException(e);
}
};
final CachedStatement cachedStatement = getStatement(sql, connectionSupplier, session, flowFile, recordParserFactory);
final PreparedStatement stmt = cachedStatement.getStatement();
final FlowFileTable<?, ?> table = cachedStatement.getTable();
table.setFlowFile(session, flowFile);
final ResultSet rs = stmt.executeQuery();
return new QueryResult() {
@Override
public void close() throws IOException {
table.close();
final BlockingQueue<CachedStatement> statementQueue = statementQueues.get(sql);
if (statementQueue == null || !statementQueue.offer(cachedStatement)) {
try {
cachedStatement.getConnection().close();
} catch (SQLException e) {
throw new IOException("Failed to close statement", e);
}
}
}
@Override
public ResultSet getResultSet() {
return rs;
}
@Override
public int getRecordsRead() {
return table.getRecordsRead();
}
};
}
Aggregations