Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions common/src/main/java/org/apache/drill/common/types/Types.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import static org.apache.drill.common.types.TypeProtos.DataMode.REPEATED;

import java.sql.ResultSetMetaData;

import org.apache.drill.common.exceptions.DrillRuntimeException;
import org.apache.drill.common.types.TypeProtos.DataMode;
import org.apache.drill.common.types.TypeProtos.MajorType;
Expand Down Expand Up @@ -169,7 +171,7 @@ public static int getJdbcTypeCode(final String sqlTypeName) {

switch (sqlTypeName) {
case "ANY": return java.sql.Types.OTHER;
case "ARRAY": return java.sql.Types.ARRAY;
case "ARRAY": return java.sql.Types.OTHER; // Drill doesn't support java.sql.Array
case "BIGINT": return java.sql.Types.BIGINT;
case "BINARY VARYING": return java.sql.Types.VARBINARY;
case "BINARY": return java.sql.Types.BINARY;
Expand All @@ -182,7 +184,7 @@ public static int getJdbcTypeCode(final String sqlTypeName) {
case "FLOAT": return java.sql.Types.FLOAT;
case "INTEGER": return java.sql.Types.INTEGER;
case "INTERVAL": return java.sql.Types.OTHER; // JDBC (4.1) has nothing for INTERVAL
case "MAP": return java.sql.Types.STRUCT;
case "MAP": return java.sql.Types.OTHER; // Drill doesn't support java.sql.Struct
case "NATIONAL CHARACTER VARYING": return java.sql.Types.NVARCHAR;
case "NATIONAL CHARACTER": return java.sql.Types.NCHAR;
case "NULL": return java.sql.Types.NULL;
Expand Down
3 changes: 2 additions & 1 deletion exec/jdbc-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@
<excludes>
<exclude>org.slf4j:jcl-over-slf4j</exclude>
<exclude>com.dyuproject.protostuff:*</exclude>
<exclude>org.apache.calcite:*</exclude>
<exclude>org.apache.calcite:calcite-core</exclude>
<exclude>org.apache.calcite:calcite-linq4j</exclude>
<exclude>org.pentaho:*</exclude>
<exclude>org.msgpack:*</exclude>
<exclude>xerces:*</exclude>
Expand Down
11 changes: 8 additions & 3 deletions exec/jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

<dependencies>
<dependency>
<groupId>net.hydromatic</groupId>
<artifactId>optiq-avatica</artifactId>
<version>0.9-drill-r20</version>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-avatica</artifactId>
<version>${avatica.version}</version>
</dependency>
<dependency>
<groupId>org.apache.drill</groupId>
Expand Down Expand Up @@ -54,6 +54,11 @@
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.Properties;
import java.util.TimeZone;

import net.hydromatic.avatica.ConnectionConfigImpl;
import org.apache.calcite.avatica.ConnectionConfigImpl;


// TODO(DRILL-3730): Change public DrillConnectionConfig from class to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
import java.util.Calendar;
import java.util.Map;

import net.hydromatic.avatica.Cursor.Accessor;

import org.apache.calcite.avatica.util.Cursor.Accessor;
import org.apache.drill.exec.vector.accessor.SqlAccessor;
import org.apache.drill.jdbc.InvalidCursorStateSqlException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
*/
package org.apache.drill.jdbc.impl;

import java.sql.ResultSet;
import java.sql.SQLException;

import net.hydromatic.avatica.Cursor.Accessor;

import org.apache.calcite.avatica.util.Cursor.Accessor;
import org.apache.drill.exec.expr.TypeHelper;
import org.apache.drill.exec.record.RecordBatchLoader;
import org.apache.drill.exec.vector.ValueVector;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@
import java.util.List;
import java.util.ListIterator;

import net.hydromatic.avatica.ColumnMetaData;
import net.hydromatic.avatica.ColumnMetaData.AvaticaType;
import net.hydromatic.avatica.ColumnMetaData.Rep;

import org.apache.calcite.avatica.ColumnMetaData;
import org.apache.calcite.avatica.ColumnMetaData.AvaticaType;
import org.apache.calcite.avatica.ColumnMetaData.Rep;
import org.apache.drill.common.types.TypeProtos.MajorType;
import org.apache.drill.common.types.Types;
import org.apache.drill.exec.proto.UserProtos.ColumnSearchability;
Expand All @@ -41,7 +40,7 @@
public class DrillColumnMetaDataList extends BasicList<ColumnMetaData>{
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DrillColumnMetaDataList.class);

private List<ColumnMetaData> columns = new ArrayList<ColumnMetaData>();
private List<ColumnMetaData> columns = new ArrayList<>();

@Override
public int size() {
Expand Down Expand Up @@ -116,7 +115,7 @@ public void updateColumnMetaData(String catalogName, String schemaName,
String tableName, BatchSchema schema,
List<Class<?>> getObjectClasses ) {
final List<ColumnMetaData> newColumns =
new ArrayList<ColumnMetaData>(schema.getFieldCount());
new ArrayList<>(schema.getFieldCount());
for (int colOffset = 0; colOffset < schema.getFieldCount(); colOffset++) {
final MaterializedField field = schema.getColumn(colOffset);
Class<?> objectClass = getObjectClasses.get( colOffset );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.SQLNonTransientConnectionException;
import java.sql.SQLTimeoutException;
import java.sql.SQLWarning;
import java.sql.SQLXML;
import java.sql.Savepoint;
Expand All @@ -40,23 +39,18 @@
import java.util.TimeZone;
import java.util.concurrent.Executor;

import net.hydromatic.avatica.AvaticaConnection;
import net.hydromatic.avatica.AvaticaFactory;
import net.hydromatic.avatica.AvaticaStatement;
import net.hydromatic.avatica.Helper;
import net.hydromatic.avatica.Meta;
import net.hydromatic.avatica.UnregisteredDriver;

import org.apache.calcite.avatica.AvaticaConnection;
import org.apache.calcite.avatica.AvaticaFactory;
import org.apache.calcite.avatica.AvaticaStatement;
import org.apache.calcite.avatica.Meta.ExecuteResult;
import org.apache.calcite.avatica.UnregisteredDriver;
import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.common.exceptions.DrillRuntimeException;
import org.apache.drill.common.exceptions.UserException;
import org.apache.drill.exec.client.DrillClient;
import org.apache.drill.exec.exception.OutOfMemoryException;
import org.apache.drill.exec.memory.BufferAllocator;
import org.apache.drill.exec.memory.RootAllocatorFactory;
import org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementResp;
import org.apache.drill.exec.proto.UserProtos.RequestStatus;
import org.apache.drill.exec.rpc.DrillRpcFuture;
import org.apache.drill.exec.rpc.RpcException;
import org.apache.drill.exec.server.Drillbit;
import org.apache.drill.exec.server.RemoteServiceSet;
Expand All @@ -69,6 +63,8 @@
import org.apache.drill.jdbc.JdbcApiSqlException;
import org.slf4j.Logger;

import com.google.common.base.Throwables;

/**
* Drill's implementation of {@link Connection}.
*/
Expand Down Expand Up @@ -163,6 +159,16 @@ protected DrillConnectionImpl(DriverImpl driver, AvaticaFactory factory,
}
}

@Override
protected ExecuteResult prepareAndExecuteInternal(AvaticaStatement statement, String sql, long maxRowCount)
throws SQLException {
try {
return super.prepareAndExecuteInternal(statement, sql, maxRowCount);
} catch(RuntimeException e) {
Throwables.propagateIfInstanceOf(e.getCause(), SQLException.class);
throw e;
}
}
/**
* Throws AlreadyClosedSqlException <i>iff</i> this Connection is closed.
*
Expand All @@ -179,15 +185,6 @@ public DrillConnectionConfig getConfig() {
return config;
}

@Override
protected Meta createMeta() {
return new MetaImpl(this);
}

MetaImpl meta() {
return (MetaImpl) meta;
}

BufferAllocator getAllocator() {
return allocator;
}
Expand Down Expand Up @@ -364,53 +361,12 @@ public PreparedStatement prepareStatement(String sql, int resultSetType,
int resultSetConcurrency,
int resultSetHoldability) throws SQLException {
throwIfClosed();
try {
DrillRpcFuture<CreatePreparedStatementResp> respFuture = client.createPreparedStatement(sql);

CreatePreparedStatementResp resp;
try {
resp = respFuture.get();
} catch (InterruptedException e) {
// Preserve evidence that the interruption occurred so that code higher up
// on the call stack can learn of the interruption and respond to it if it
// wants to.
Thread.currentThread().interrupt();

throw new SQLException( "Interrupted", e );
}

final RequestStatus status = resp.getStatus();
if (status != RequestStatus.OK) {
final String errMsgFromServer = resp.getError() != null ? resp.getError().getMessage() : "";

if (status == RequestStatus.TIMEOUT) {
logger.error("Request timed out to create prepare statement: {}", errMsgFromServer);
throw new SQLTimeoutException("Failed to create prepared statement: " + errMsgFromServer);
}

if (status == RequestStatus.FAILED) {
logger.error("Failed to create prepared statement: {}", errMsgFromServer);
throw new SQLException("Failed to create prepared statement: " + errMsgFromServer);
}

logger.error("Failed to create prepared statement. Unknown status: {}, Error: {}", status, errMsgFromServer);
throw new SQLException(String.format(
"Failed to create prepared statement. Unknown status: %s, Error: %s", status, errMsgFromServer));
}

DrillPrepareResult prepareResult = new DrillPrepareResult(sql, resp.getPreparedStatement());
DrillPreparedStatementImpl statement =
(DrillPreparedStatementImpl) factory.newPreparedStatement(
this, prepareResult, resultSetType, resultSetConcurrency,
resultSetHoldability);
return statement;
} catch (SQLException e) {
throw e;
} catch (RuntimeException e) {
throw Helper.INSTANCE.createException("Error while preparing statement [" + sql + "]", e);
} catch (Exception e) {
throw Helper.INSTANCE.createException("Error while preparing statement [" + sql + "]", e);
}
DrillPreparedStatementImpl statement =
(DrillPreparedStatementImpl) super.prepareStatement(sql,
resultSetType,
resultSetConcurrency,
resultSetHoldability);
return statement;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,25 @@
*/
package org.apache.drill.jdbc.impl;

import java.sql.SQLException;
import java.sql.ResultSet;
import static org.slf4j.LoggerFactory.getLogger;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import net.hydromatic.avatica.ArrayImpl.Factory;
import net.hydromatic.avatica.ColumnMetaData;
import net.hydromatic.avatica.Cursor;
import net.hydromatic.avatica.AvaticaResultSet;

import org.apache.drill.common.exceptions.DrillRuntimeException;
import org.apache.calcite.avatica.AvaticaResultSet;
import org.apache.calcite.avatica.ColumnMetaData;
import org.apache.calcite.avatica.util.ArrayImpl.Factory;
import org.apache.calcite.avatica.util.Cursor;
import org.apache.drill.common.exceptions.UserException;
import org.apache.drill.exec.exception.SchemaChangeException;
import org.apache.drill.exec.record.BatchSchema;
import org.apache.drill.exec.record.RecordBatchLoader;
import org.apache.drill.exec.rpc.user.QueryDataBatch;
import org.apache.drill.exec.store.ischema.InfoSchemaConstants;
import org.slf4j.Logger;
import static org.slf4j.LoggerFactory.getLogger;


class DrillCursor implements Cursor {
Expand Down Expand Up @@ -134,7 +132,7 @@ private void updateColumns() {
// DrillAccessorList blocks iterator() (throwing exception).)
for ( int ax = 0; ax < accessors.size(); ax++ ) {
final AvaticaDrillSqlAccessor accessor =
(AvaticaDrillSqlAccessor) accessors.get( ax );
accessors.get( ax );
getObjectClasses.add( accessor.getObjectClass() );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;

import org.apache.calcite.avatica.AvaticaConnection;
import org.apache.calcite.avatica.AvaticaDatabaseMetaData;
import org.apache.drill.jdbc.AlreadyClosedSqlException;
import org.apache.drill.jdbc.DrillDatabaseMetaData;

import net.hydromatic.avatica.AvaticaConnection;
import net.hydromatic.avatica.AvaticaDatabaseMetaData;


/**
* Drill's implementation of {@link DatabaseMetaData}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import java.sql.SQLException;
import java.util.Properties;

import net.hydromatic.avatica.AvaticaConnection;
import net.hydromatic.avatica.AvaticaFactory;
import net.hydromatic.avatica.UnregisteredDriver;
import org.apache.calcite.avatica.AvaticaConnection;
import org.apache.calcite.avatica.AvaticaFactory;
import org.apache.calcite.avatica.UnregisteredDriver;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

import java.sql.SQLException;

import net.hydromatic.avatica.AvaticaConnection;
import net.hydromatic.avatica.AvaticaStatement;
import net.hydromatic.avatica.Handler;
import org.apache.calcite.avatica.AvaticaConnection;
import org.apache.calcite.avatica.AvaticaStatement;
import org.apache.calcite.avatica.Handler;

class DrillHandler implements Handler {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DrillHandler.class);
Expand Down
Loading