http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/core/src/main/java/org/apache/calcite/avatica/util/Unsafe.java ---------------------------------------------------------------------- diff --git a/avatica/core/src/main/java/org/apache/calcite/avatica/util/Unsafe.java b/avatica/core/src/main/java/org/apache/calcite/avatica/util/Unsafe.java deleted file mode 100644 index 1d0238c..0000000 --- a/avatica/core/src/main/java/org/apache/calcite/avatica/util/Unsafe.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.calcite.avatica.util; - -import java.util.Calendar; -import java.util.Locale; - -/** - * Contains methods that call JDK methods that the - * <a href="https://github.com/policeman-tools/forbidden-apis">forbidden - * APIs checker</a> does not approve of. - * - * <p>This class is excluded from the check, so methods called via this class - * will not fail the build. - */ -public class Unsafe { - private Unsafe() {} - - /** Calls {@link System#exit}. */ - public static void systemExit(int status) { - System.exit(status); - } - - /** Calls {@link Object#notifyAll()}. */ - public static void notifyAll(Object o) { - o.notifyAll(); - } - - /** Calls {@link Object#wait()}. */ - public static void wait(Object o) throws InterruptedException { - o.wait(); - } - - /** Returns a {@link java.util.Calendar} with the local time zone and root - * locale. */ - public static Calendar localCalendar() { - return Calendar.getInstance(Locale.ROOT); - } -} - -// End Unsafe.java
http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/core/src/main/java/org/apache/calcite/avatica/util/UnsynchronizedBuffer.java ---------------------------------------------------------------------- diff --git a/avatica/core/src/main/java/org/apache/calcite/avatica/util/UnsynchronizedBuffer.java b/avatica/core/src/main/java/org/apache/calcite/avatica/util/UnsynchronizedBuffer.java deleted file mode 100644 index 8daee60..0000000 --- a/avatica/core/src/main/java/org/apache/calcite/avatica/util/UnsynchronizedBuffer.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.calcite.avatica.util; - -import java.io.IOException; -import java.io.OutputStream; - -/** - * A utility class for reading and writing bytes to byte buffers without synchronization. A - * reduced variant taken from Apache Accumulo. This class is <b>not</b> thread-safe by design. - * It is up to the caller to guarantee mutual exclusion as necessary. - */ -public class UnsynchronizedBuffer extends OutputStream { - // Anything larger than 64K, reap the backing buffer - private static final int LARGE_BUFFER_SIZE = 1024 * 64; - - final int initialCapacity; - int offset = 0; - byte[] data; - - /** - * Creates a new writer. - */ - public UnsynchronizedBuffer() { - this(4096); - } - - /** - * Creates a new writer. - * - * @param initialCapacity initial byte capacity - */ - public UnsynchronizedBuffer(int initialCapacity) { - this.initialCapacity = initialCapacity; - data = new byte[initialCapacity]; - } - - private void reserve(int l) { - if (offset + l > data.length) { - int newSize = UnsynchronizedBuffer.nextArraySize(offset + l); - - byte[] newData = new byte[newSize]; - System.arraycopy(data, 0, newData, 0, offset); - data = newData; - } - - } - - /** - * Adds bytes to this writer's buffer. - * - * @param bytes byte array - * @param off offset into array to start copying bytes - * @param length number of bytes to add - * @throws IndexOutOfBoundsException if off or length are invalid - */ - public void write(byte[] bytes, int off, int length) { - reserve(length); - System.arraycopy(bytes, off, data, offset, length); - offset += length; - } - - @Override public void write(int b) throws IOException { - reserve(1); - data[offset] = (byte) b; - offset++; - } - - /** - * Gets (a copy of) the contents of this writer's buffer. - * - * @return byte buffer contents - */ - public byte[] toArray() { - byte[] ret = new byte[offset]; - System.arraycopy(data, 0, ret, 0, offset); - return ret; - } - - /** - * Resets the internal pointer into the buffer. - */ - public void reset() { - offset = 0; - if (data.length >= LARGE_BUFFER_SIZE) { - data = new byte[this.initialCapacity]; - } - } - - /** - * @return The current offset into the backing array. - */ - public int getOffset() { - return offset; - } - - /** - * @return The current length of the backing array. - */ - public long getSize() { - return data.length; - } - - /** - * Determines what next array size should be by rounding up to next power of two. - * - * @param i current array size - * @return next array size - * @throws IllegalArgumentException if i is negative - */ - public static int nextArraySize(int i) { - if (i < 0) { - throw new IllegalArgumentException(); - } - - if (i > (1 << 30)) { - return Integer.MAX_VALUE; // this is the next power of 2 minus one... a special case - } - - if (i == 0) { - return 1; - } - - // round up to next power of two - int ret = i; - ret--; - ret |= ret >> 1; - ret |= ret >> 2; - ret |= ret >> 4; - ret |= ret >> 8; - ret |= ret >> 16; - ret++; - - return ret; - } -} - -// End UnsynchronizedBuffer.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/core/src/main/java/org/apache/calcite/avatica/util/package-info.java ---------------------------------------------------------------------- diff --git a/avatica/core/src/main/java/org/apache/calcite/avatica/util/package-info.java b/avatica/core/src/main/java/org/apache/calcite/avatica/util/package-info.java deleted file mode 100644 index eab457c..0000000 --- a/avatica/core/src/main/java/org/apache/calcite/avatica/util/package-info.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Avatica utilities. - */ -@PackageMarker -package org.apache.calcite.avatica.util; - -// End package-info.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/core/src/main/protobuf/common.proto ---------------------------------------------------------------------- diff --git a/avatica/core/src/main/protobuf/common.proto b/avatica/core/src/main/protobuf/common.proto deleted file mode 100644 index affe5d5..0000000 --- a/avatica/core/src/main/protobuf/common.proto +++ /dev/null @@ -1,275 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -syntax = "proto3"; - -option java_package = "org.apache.calcite.avatica.proto"; - -// Details about a connection -message ConnectionProperties { - bool is_dirty = 1; - bool auto_commit = 2; - bool has_auto_commit = 7; // field is a Boolean, need to discern null and default value - bool read_only = 3; - bool has_read_only = 8; // field is a Boolean, need to discern null and default value - uint32 transaction_isolation = 4; - string catalog = 5; - string schema = 6; -} - -// Statement handle -message StatementHandle { - string connection_id = 1; - uint32 id = 2; - Signature signature = 3; -} - -// Results of preparing a statement -message Signature { - repeated ColumnMetaData columns = 1; - string sql = 2; - repeated AvaticaParameter parameters = 3; - CursorFactory cursor_factory = 4; - StatementType statementType = 5; -} - -// Has to be consistent with Meta.StatementType -enum StatementType { - SELECT = 0; - INSERT = 1; - UPDATE = 2; - DELETE = 3; - UPSERT = 4; - MERGE = 5; - OTHER_DML = 6; - CREATE = 7; - DROP = 8; - ALTER = 9; - OTHER_DDL = 10; - CALL = 11; -} - -message ColumnMetaData { - uint32 ordinal = 1; - bool auto_increment = 2; - bool case_sensitive = 3; - bool searchable = 4; - bool currency = 5; - uint32 nullable = 6; - bool signed = 7; - uint32 display_size = 8; - string label = 9; - string column_name = 10; - string schema_name = 11; - uint32 precision = 12; - uint32 scale = 13; - string table_name = 14; - string catalog_name = 15; - bool read_only = 16; - bool writable = 17; - bool definitely_writable = 18; - string column_class_name = 19; - AvaticaType type = 20; -} - -enum Rep { - PRIMITIVE_BOOLEAN = 0; - PRIMITIVE_BYTE = 1; - PRIMITIVE_CHAR = 2; - PRIMITIVE_SHORT = 3; - PRIMITIVE_INT = 4; - PRIMITIVE_LONG = 5; - PRIMITIVE_FLOAT = 6; - PRIMITIVE_DOUBLE = 7; - BOOLEAN = 8; - BYTE = 9; - CHARACTER = 10; - SHORT = 11; - INTEGER = 12; - LONG = 13; - FLOAT = 14; - DOUBLE = 15; - BIG_INTEGER = 25; - BIG_DECIMAL = 26; - JAVA_SQL_TIME = 16; - JAVA_SQL_TIMESTAMP = 17; - JAVA_SQL_DATE = 18; - JAVA_UTIL_DATE = 19; - BYTE_STRING = 20; - STRING = 21; - NUMBER = 22; - OBJECT = 23; - NULL = 24; - ARRAY = 27; - STRUCT = 28; - MULTISET = 29; -} - -// Base class for a column type -message AvaticaType { - uint32 id = 1; - string name = 2; - Rep rep = 3; - - repeated ColumnMetaData columns = 4; // Only present when name = STRUCT - AvaticaType component = 5; // Only present when name = ARRAY -} - -// Metadata for a parameter -message AvaticaParameter { - bool signed = 1; - uint32 precision = 2; - uint32 scale = 3; - uint32 parameter_type = 4; - string type_name = 5; - string class_name = 6; - string name = 7; -} - -// Information necessary to convert an Iterable into a Calcite Cursor -message CursorFactory { - enum Style { - OBJECT = 0; - RECORD = 1; - RECORD_PROJECTION = 2; - ARRAY = 3; - LIST = 4; - MAP = 5; - } - - Style style = 1; - string class_name = 2; - repeated string field_names = 3; -} - -// A collection of rows -message Frame { - uint64 offset = 1; - bool done = 2; - repeated Row rows = 3; -} - -// A row is a collection of values -message Row { - repeated ColumnValue value = 1; -} - -// Database property, list of functions the database provides for a certain operation -message DatabaseProperty { - string name = 1; - repeated string functions = 2; -} - -// Message which encapsulates another message to support a single RPC endpoint -message WireMessage { - string name = 1; - bytes wrapped_message = 2; -} - -// A value might be a TypedValue or an Array of TypedValue's -message ColumnValue { - repeated TypedValue value = 1; // deprecated, use array_value or scalar_value - repeated TypedValue array_value = 2; - bool has_array_value = 3; // Is an array value set? - TypedValue scalar_value = 4; -} - -// Generic wrapper to support any SQL type. Struct-like to work around no polymorphism construct. -message TypedValue { - Rep type = 1; // The actual type that was serialized in the general attribute below - - bool bool_value = 2; // boolean - string string_value = 3; // char/varchar - sint64 number_value = 4; // var-len encoding lets us shove anything from byte to long - // includes numeric types and date/time types. - bytes bytes_value = 5; // binary/varbinary - double double_value = 6; // big numbers - bool null = 7; // a null object -} - -// The severity of some unexpected outcome to an operation. -// Protobuf enum values must be unique across all other enums -enum Severity { - UNKNOWN_SEVERITY = 0; - FATAL_SEVERITY = 1; - ERROR_SEVERITY = 2; - WARNING_SEVERITY = 3; -} - -// Enumeration corresponding to DatabaseMetaData operations -enum MetaDataOperation { - GET_ATTRIBUTES = 0; - GET_BEST_ROW_IDENTIFIER = 1; - GET_CATALOGS = 2; - GET_CLIENT_INFO_PROPERTIES = 3; - GET_COLUMN_PRIVILEGES = 4; - GET_COLUMNS = 5; - GET_CROSS_REFERENCE = 6; - GET_EXPORTED_KEYS = 7; - GET_FUNCTION_COLUMNS = 8; - GET_FUNCTIONS = 9; - GET_IMPORTED_KEYS = 10; - GET_INDEX_INFO = 11; - GET_PRIMARY_KEYS = 12; - GET_PROCEDURE_COLUMNS = 13; - GET_PROCEDURES = 14; - GET_PSEUDO_COLUMNS = 15; - GET_SCHEMAS = 16; - GET_SCHEMAS_WITH_ARGS = 17; - GET_SUPER_TABLES = 18; - GET_SUPER_TYPES = 19; - GET_TABLE_PRIVILEGES = 20; - GET_TABLES = 21; - GET_TABLE_TYPES = 22; - GET_TYPE_INFO = 23; - GET_UDTS = 24; - GET_VERSION_COLUMNS = 25; -} - -// Represents the breadth of arguments to DatabaseMetaData functions -message MetaDataOperationArgument { - enum ArgumentType { - STRING = 0; - BOOL = 1; - INT = 2; - REPEATED_STRING = 3; - REPEATED_INT = 4; - NULL = 5; - } - - string string_value = 1; - bool bool_value = 2; - sint32 int_value = 3; - repeated string string_array_values = 4; - repeated sint32 int_array_values = 5; - ArgumentType type = 6; -} - -enum StateType { - SQL = 0; - METADATA = 1; -} - -message QueryState { - StateType type = 1; - string sql = 2; - MetaDataOperation op = 3; - repeated MetaDataOperationArgument args = 4; - bool has_args = 5; - bool has_sql = 6; - bool has_op = 7; -} http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/core/src/main/protobuf/requests.proto ---------------------------------------------------------------------- diff --git a/avatica/core/src/main/protobuf/requests.proto b/avatica/core/src/main/protobuf/requests.proto deleted file mode 100644 index 228be27..0000000 --- a/avatica/core/src/main/protobuf/requests.proto +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -syntax = "proto3"; - -option java_package = "org.apache.calcite.avatica.proto"; - -import "common.proto"; - -// Request for Meta#getCatalogs() -message CatalogsRequest { - string connection_id = 1; -} - -// Request for Meta#getDatabaseProperties() -message DatabasePropertyRequest { - string connection_id = 1; -} - -// Request for Meta#getSchemas(String, org.apache.calcite.avatica.Meta.Pat)} -message SchemasRequest { - string catalog = 1; - string schema_pattern = 2; - string connection_id = 3; -} - -// Request for Request for Meta#getTables(String, org.apache.calcite.avatica.Meta.Pat, -// org.apache.calcite.avatica.Meta.Pat, java.util.List) -message TablesRequest { - string catalog = 1; - string schema_pattern = 2; - string table_name_pattern = 3; - repeated string type_list = 4; - bool has_type_list = 6; // Having an empty type_list is distinct from a null type_list - string connection_id = 7; -} - -// Request for Meta#getTableTypes() -message TableTypesRequest { - string connection_id = 1; -} - -// Request for Meta#getColumns(String, org.apache.calcite.avatica.Meta.Pat, -// org.apache.calcite.avatica.Meta.Pat, org.apache.calcite.avatica.Meta.Pat). -message ColumnsRequest { - string catalog = 1; - string schema_pattern = 2; - string table_name_pattern = 3; - string column_name_pattern = 4; - string connection_id = 5; -} - -// Request for Meta#getTypeInfo() -message TypeInfoRequest { - string connection_id = 1; -} - -// Request for Meta#prepareAndExecute(Meta.StatementHandle, String, long, Meta.PrepareCallback) -message PrepareAndExecuteRequest { - string connection_id = 1; - string sql = 2; - uint64 max_row_count = 3; // Deprecated - uint32 statement_id = 4; - int64 max_rows_total = 5; // The maximum number of rows that will be allowed for this query - int32 first_frame_max_size = 6; // The maximum number of rows that will be returned in the - // first Frame returned for this query. -} - -// Request for Meta.prepare(Meta.ConnectionHandle, String, long) -message PrepareRequest { - string connection_id = 1; - string sql = 2; - uint64 max_row_count = 3; // Deprecated - int64 max_rows_total = 4; // The maximum number of rows that will be allowed for this query -} - -// Request for Meta#fetch(Meta.StatementHandle, List, long, int) -message FetchRequest { - string connection_id = 1; - uint32 statement_id = 2; - uint64 offset = 3; - uint32 fetch_max_row_count = 4; // Maximum number of rows to be returned in the frame. Negative means no limit. Deprecated! - int32 frame_max_size = 5; -} - -// Request for Meta#createStatement(Meta.ConnectionHandle) -message CreateStatementRequest { - string connection_id = 1; -} - -// Request for Meta#closeStatement(Meta.StatementHandle) -message CloseStatementRequest { - string connection_id = 1; - uint32 statement_id = 2; -} - -// Request for Meta#openConnection(Meta.ConnectionHandle, Map<String, String>) -message OpenConnectionRequest { - string connection_id = 1; - map<string, string> info = 2; -} - -// Request for Meta#closeConnection(Meta.ConnectionHandle) -message CloseConnectionRequest { - string connection_id = 1; -} - -message ConnectionSyncRequest { - string connection_id = 1; - ConnectionProperties conn_props = 2; -} - -// Request for Meta#execute(Meta.ConnectionHandle, list, long) -message ExecuteRequest { - StatementHandle statementHandle = 1; - repeated TypedValue parameter_values = 2; - uint64 first_frame_max_size = 3; // The maximum number of rows to return in the first Frame - bool has_parameter_values = 4; -} - - -message SyncResultsRequest { - string connection_id = 1; - uint32 statement_id = 2; - QueryState state = 3; - uint64 offset = 4; -} - -// Request to invoke a commit on a Connection -message CommitRequest { - string connection_id = 1; -} - -// Request to invoke rollback on a Connection -message RollbackRequest { - string connection_id = 1; -} - -// Request to prepare and execute a collection of sql statements. -message PrepareAndExecuteBatchRequest { - string connection_id = 1; - uint32 statement_id = 2; - repeated string sql_commands = 3; -} - -// Each command is a list of TypedValues -message UpdateBatch { - repeated TypedValue parameter_values = 1; -} - -message ExecuteBatchRequest { - string connection_id = 1; - uint32 statement_id = 2; - repeated UpdateBatch updates = 3; // A batch of updates is a list<list<typevalue>> -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/core/src/main/protobuf/responses.proto ---------------------------------------------------------------------- diff --git a/avatica/core/src/main/protobuf/responses.proto b/avatica/core/src/main/protobuf/responses.proto deleted file mode 100644 index a3cd3d2..0000000 --- a/avatica/core/src/main/protobuf/responses.proto +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -syntax = "proto3"; - -option java_package = "org.apache.calcite.avatica.proto"; - -import "common.proto"; - -// Response that contains a result set. -message ResultSetResponse { - string connection_id = 1; - uint32 statement_id = 2; - bool own_statement = 3; - Signature signature = 4; - Frame first_frame = 5; - uint64 update_count = 6; // -1 for normal result sets, else this response contains a dummy result set - // with no signature nor other data. - RpcMetadata metadata = 7; -} - -// Response to PrepareAndExecuteRequest -message ExecuteResponse { - repeated ResultSetResponse results = 1; - bool missing_statement = 2; // Did the request fail because of no-cached statement - RpcMetadata metadata = 3; -} - -// Response to PrepareRequest -message PrepareResponse { - StatementHandle statement = 1; - RpcMetadata metadata = 2; -} - -// Response to FetchRequest -message FetchResponse { - Frame frame = 1; - bool missing_statement = 2; // Did the request fail because of no-cached statement - bool missing_results = 3; // Did the request fail because of a cached-statement w/o ResultSet - RpcMetadata metadata = 4; -} - -// Response to CreateStatementRequest -message CreateStatementResponse { - string connection_id = 1; - uint32 statement_id = 2; - RpcMetadata metadata = 3; -} - -// Response to CloseStatementRequest -message CloseStatementResponse { - RpcMetadata metadata = 1; -} - -// Response to OpenConnectionRequest { -message OpenConnectionResponse { - RpcMetadata metadata = 1; -} - -// Response to CloseConnectionRequest { -message CloseConnectionResponse { - RpcMetadata metadata = 1; -} - -// Response to ConnectionSyncRequest -message ConnectionSyncResponse { - ConnectionProperties conn_props = 1; - RpcMetadata metadata = 2; -} - -message DatabasePropertyElement { - DatabaseProperty key = 1; - TypedValue value = 2; - RpcMetadata metadata = 3; -} - -// Response for Meta#getDatabaseProperties() -message DatabasePropertyResponse { - repeated DatabasePropertyElement props = 1; - RpcMetadata metadata = 2; -} - -// Send contextual information about some error over the wire from the server. -message ErrorResponse { - repeated string exceptions = 1; // exception stacktraces, many for linked exceptions. - bool has_exceptions = 7; // are there stacktraces contained? - string error_message = 2; // human readable description - Severity severity = 3; - uint32 error_code = 4; // numeric identifier for error - string sql_state = 5; // five-character standard-defined value - RpcMetadata metadata = 6; -} - -message SyncResultsResponse { - bool missing_statement = 1; // Server doesn't have the statement with the ID from the request - bool more_results = 2; // Should the client fetch() to get more results - RpcMetadata metadata = 3; -} - -// Generic metadata for the server to return with each response. -message RpcMetadata { - string server_address = 1; // The host:port of the server -} - -// Response to a commit request -message CommitResponse { - -} - -// Response to a rollback request -message RollbackResponse { - -} - -// Response to a batch update request -message ExecuteBatchResponse { - string connection_id = 1; - uint32 statement_id = 2; - repeated uint64 update_counts = 3; - bool missing_statement = 4; // Did the request fail because of no-cached statement - RpcMetadata metadata = 5; -} http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/core/src/main/resources/META-INF/services/java.sql.Driver ---------------------------------------------------------------------- diff --git a/avatica/core/src/main/resources/META-INF/services/java.sql.Driver b/avatica/core/src/main/resources/META-INF/services/java.sql.Driver deleted file mode 100644 index beb1ac0..0000000 --- a/avatica/core/src/main/resources/META-INF/services/java.sql.Driver +++ /dev/null @@ -1 +0,0 @@ -org.apache.calcite.avatica.remote.Driver http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/core/src/test/java/org/apache/calcite/avatica/AvaticaConnectionTest.java ---------------------------------------------------------------------- diff --git a/avatica/core/src/test/java/org/apache/calcite/avatica/AvaticaConnectionTest.java b/avatica/core/src/test/java/org/apache/calcite/avatica/AvaticaConnectionTest.java deleted file mode 100644 index b1c003f..0000000 --- a/avatica/core/src/test/java/org/apache/calcite/avatica/AvaticaConnectionTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.calcite.avatica; - -import org.junit.Assert; -import org.junit.Test; -import org.mockito.Mockito; - -import java.util.Properties; - -/** - * Tests for AvaticaConnection - */ -public class AvaticaConnectionTest { - - @Test - public void testNumExecuteRetries() { - AvaticaConnection statement = Mockito.mock(AvaticaConnection.class); - - Mockito.when(statement.getNumStatementRetries(Mockito.nullable(Properties.class))) - .thenCallRealMethod(); - - // Bad argument should throw an exception - try { - statement.getNumStatementRetries(null); - Assert.fail("Calling getNumStatementRetries with a null object should throw an exception"); - } catch (NullPointerException e) { - // Pass - } - - Properties props = new Properties(); - - // Verify the default value - Assert.assertEquals(Long.valueOf(AvaticaConnection.NUM_EXECUTE_RETRIES_DEFAULT).longValue(), - statement.getNumStatementRetries(props)); - - // Set a non-default value - props.setProperty(AvaticaConnection.NUM_EXECUTE_RETRIES_KEY, "10"); - - // Verify that we observe that value - Assert.assertEquals(10, statement.getNumStatementRetries(props)); - } - -} - -// End AvaticaConnectionTest.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/core/src/test/java/org/apache/calcite/avatica/AvaticaResultSetConversionsTest.java ---------------------------------------------------------------------- diff --git a/avatica/core/src/test/java/org/apache/calcite/avatica/AvaticaResultSetConversionsTest.java b/avatica/core/src/test/java/org/apache/calcite/avatica/AvaticaResultSetConversionsTest.java deleted file mode 100644 index bf3047f..0000000 --- a/avatica/core/src/test/java/org/apache/calcite/avatica/AvaticaResultSetConversionsTest.java +++ /dev/null @@ -1,1100 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.calcite.avatica; - -import org.apache.calcite.avatica.ColumnMetaData.AvaticaType; -import org.apache.calcite.avatica.remote.TypedValue; -import org.apache.calcite.avatica.util.DateTimeUtils; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; - -import java.math.BigDecimal; -import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.Date; -import java.sql.ResultSet; -import java.sql.SQLDataException; -import java.sql.SQLException; -import java.sql.Time; -import java.sql.Timestamp; -import java.sql.Types; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -import static org.hamcrest.CoreMatchers.isA; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; - -/** - * Test {@code ResultSet#getXXX} conversions. - */ -@RunWith(Parameterized.class) -public class AvaticaResultSetConversionsTest { - /** - * A fake test driver for test. - */ - private static final class TestDriver extends UnregisteredDriver { - - @Override protected DriverVersion createDriverVersion() { - return new DriverVersion("test", "test 0.0.0", "test", "test 0.0.0", false, 0, 0, 0, 0); - } - - @Override protected String getConnectStringPrefix() { - return "jdbc:test"; - } - - @Override public Meta createMeta(AvaticaConnection connection) { - return new TestMetaImpl(connection); - } - } - - /** - * Fake meta implementation for test driver. - */ - public static final class TestMetaImpl extends MetaImpl { - public TestMetaImpl(AvaticaConnection connection) { - super(connection); - } - - @Override public StatementHandle prepare(ConnectionHandle ch, String sql, long maxRowCount) { - throw new UnsupportedOperationException(); - } - - @SuppressWarnings("deprecation") - @Override public ExecuteResult prepareAndExecute(StatementHandle h, String sql, - long maxRowCount, PrepareCallback callback) throws NoSuchStatementException { - throw new UnsupportedOperationException(); - } - - private static ColumnMetaData columnMetaData(String name, int ordinal, AvaticaType type, - int columnNullable) { - return new ColumnMetaData( - ordinal, false, true, false, false, - columnNullable, - true, -1, name, name, null, - 0, 0, null, null, type, true, false, false, - type.columnClassName()); - } - - @Override public ExecuteResult prepareAndExecute(StatementHandle h, String sql, - long maxRowCount, int maxRowsInFirstFrame, PrepareCallback callback) - throws NoSuchStatementException { - assertEquals("SELECT * FROM TABLE", sql); - List<ColumnMetaData> columns = Arrays.asList( - columnMetaData("bool", 0, - ColumnMetaData.scalar(Types.BOOLEAN, "BOOLEAN", - ColumnMetaData.Rep.PRIMITIVE_BOOLEAN), - DatabaseMetaData.columnNoNulls), - columnMetaData("byte", 1, - ColumnMetaData.scalar(Types.TINYINT, "TINYINT", - ColumnMetaData.Rep.PRIMITIVE_BYTE), - DatabaseMetaData.columnNoNulls), - columnMetaData("short", 2, - ColumnMetaData.scalar(Types.SMALLINT, "SMALLINT", - ColumnMetaData.Rep.PRIMITIVE_SHORT), - DatabaseMetaData.columnNoNulls), - columnMetaData("int", 3, - ColumnMetaData.scalar(Types.INTEGER, "INTEGER", - ColumnMetaData.Rep.PRIMITIVE_INT), - DatabaseMetaData.columnNoNulls), - columnMetaData("long", 4, - ColumnMetaData.scalar(Types.BIGINT, "BIGINT", - ColumnMetaData.Rep.PRIMITIVE_LONG), - DatabaseMetaData.columnNoNulls), - columnMetaData("float", 5, - ColumnMetaData.scalar(Types.REAL, "REAL", - ColumnMetaData.Rep.FLOAT), - DatabaseMetaData.columnNoNulls), - columnMetaData("double", 6, - ColumnMetaData.scalar(Types.FLOAT, "FLOAT", - ColumnMetaData.Rep.DOUBLE), - DatabaseMetaData.columnNoNulls), - columnMetaData("string", 7, - ColumnMetaData.scalar(Types.VARCHAR, "VARCHAR", - ColumnMetaData.Rep.STRING), - DatabaseMetaData.columnNoNulls), - columnMetaData("date", 8, - ColumnMetaData.scalar(Types.DATE, "DATE", - ColumnMetaData.Rep.JAVA_SQL_DATE), - DatabaseMetaData.columnNoNulls), - columnMetaData("time", 9, - ColumnMetaData.scalar(Types.TIME, "TIME", - ColumnMetaData.Rep.JAVA_SQL_TIME), - DatabaseMetaData.columnNoNulls), - columnMetaData("timestamp", 10, - ColumnMetaData.scalar(Types.TIMESTAMP, "TIMESTAMP", - ColumnMetaData.Rep.JAVA_SQL_TIMESTAMP), - DatabaseMetaData.columnNoNulls)); - - List<Object> row = Collections.<Object>singletonList( - new Object[] { - true, (byte) 1, (short) 2, 3, 4L, 5.0f, 6.0d, "testvalue", - new Date(1476130718123L), new Time(1476130718123L), - new Timestamp(1476130718123L) - }); - - CursorFactory factory = CursorFactory.deduce(columns, null); - Frame frame = new Frame(0, true, row); - - Signature signature = Signature.create(columns, sql, - Collections.<AvaticaParameter>emptyList(), factory, StatementType.SELECT); - try { - synchronized (callback.getMonitor()) { - callback.clear(); - callback.assign(signature, frame, -1); - } - callback.execute(); - } catch (SQLException e) { - throw new RuntimeException(); - } - MetaResultSet rs = MetaResultSet.create(h.connectionId, 0, false, signature, null); - return new ExecuteResult(Collections.singletonList(rs)); - } - - @Override public ExecuteBatchResult prepareAndExecuteBatch(StatementHandle h, - List<String> sqlCommands) throws NoSuchStatementException { - throw new UnsupportedOperationException(); - } - - @Override public ExecuteBatchResult executeBatch(StatementHandle h, - List<List<TypedValue>> parameterValues) throws NoSuchStatementException { - throw new UnsupportedOperationException(); - } - - @Override public Frame fetch(StatementHandle h, long offset, int fetchMaxRowCount) - throws NoSuchStatementException, MissingResultsException { - throw new UnsupportedOperationException(); - } - - @SuppressWarnings("deprecation") - @Override public ExecuteResult execute(StatementHandle h, List<TypedValue> parameterValues, - long maxRowCount) throws NoSuchStatementException { - throw new UnsupportedOperationException(); - } - - @Override public ExecuteResult execute(StatementHandle h, List<TypedValue> parameterValues, - int maxRowsInFirstFrame) throws NoSuchStatementException { - throw new UnsupportedOperationException(); - } - - @Override public void closeStatement(StatementHandle h) { - } - - @Override public boolean syncResults(StatementHandle sh, QueryState state, long offset) - throws NoSuchStatementException { - throw new UnsupportedOperationException(); - } - - @Override public void commit(ConnectionHandle ch) { - throw new UnsupportedOperationException(); - } - - @Override public void rollback(ConnectionHandle ch) { - throw new UnsupportedOperationException(); - } - } - - /** - * Base accessor test helper - */ - private static class AccessorTestHelper { - protected final int ordinal; - - protected AccessorTestHelper(int ordinal) { - this.ordinal = ordinal; - } - - public void testGetString(ResultSet resultSet) throws SQLException { - resultSet.getString(ordinal); - } - - public void testGetBoolean(ResultSet resultSet) throws SQLException { - try { - resultSet.getBoolean(ordinal); - fail("Was expecting to throw SQLDataException"); - } catch (Exception e) { - assertThat(e, isA((Class) SQLDataException.class)); // success - } - } - - public void testGetByte(ResultSet resultSet) throws SQLException { - try { - resultSet.getByte(ordinal); - fail("Was expecting to throw SQLDataException"); - } catch (Exception e) { - assertThat(e, isA((Class) SQLDataException.class)); // success - } - } - - public void testGetShort(ResultSet resultSet) throws SQLException { - try { - resultSet.getShort(ordinal); - fail("Was expecting to throw SQLDataException"); - } catch (Exception e) { - assertThat(e, isA((Class) SQLDataException.class)); // success - } - } - - public void testGetInt(ResultSet resultSet) throws SQLException { - try { - resultSet.getInt(ordinal); - fail("Was expecting to throw SQLDataException"); - } catch (Exception e) { - assertThat(e, isA((Class) SQLDataException.class)); // success - } - } - - public void testGetLong(ResultSet resultSet) throws SQLException { - try { - resultSet.getLong(ordinal); - fail("Was expecting to throw SQLDataException"); - } catch (Exception e) { - assertThat(e, isA((Class) SQLDataException.class)); // success - } - } - - public void testGetFloat(ResultSet resultSet) throws SQLException { - try { - resultSet.getFloat(ordinal); - fail("Was expecting to throw SQLDataException"); - } catch (Exception e) { - assertThat(e, isA((Class) SQLDataException.class)); // success - } - } - - public void testGetDouble(ResultSet resultSet) throws SQLException { - try { - resultSet.getDouble(ordinal); - fail("Was expecting to throw SQLDataException"); - } catch (Exception e) { - assertThat(e, isA((Class) SQLDataException.class)); // success - } - } - - public void testGetDecimal(ResultSet resultSet) throws SQLException { - try { - resultSet.getBigDecimal(ordinal); - fail("Was expecting to throw SQLDataException"); - } catch (Exception e) { - assertThat(e, isA((Class) SQLDataException.class)); // success - } - } - - public void testGetBytes(ResultSet resultSet) throws SQLException { - try { - resultSet.getBytes(ordinal); - fail("Was expecting to throw SQLDataException"); - } catch (Exception e) { - assertThat(e, isA((Class) SQLDataException.class)); // success - } - } - - public void testGetAsciiStream(ResultSet resultSet) throws SQLException { - try { - resultSet.getAsciiStream(ordinal); - fail("Was expecting to throw SQLDataException"); - } catch (Exception e) { - assertThat(e, isA((Class) SQLDataException.class)); // success - } - } - - public void testGetBinaryStream(ResultSet resultSet) throws SQLException { - try { - resultSet.getBinaryStream(ordinal); - fail("Was expecting to throw SQLDataException"); - } catch (Exception e) { - assertThat(e, isA((Class) SQLDataException.class)); // success - } - } - - public void testGetObject(ResultSet resultSet) throws SQLException { - resultSet.getObject(ordinal); - } - - public void testGetCharacterStream(ResultSet resultSet) throws SQLException { - try { - resultSet.getCharacterStream(ordinal); - fail("Was expecting to throw SQLDataException"); - } catch (Exception e) { - assertThat(e, isA((Class) SQLDataException.class)); // success - } - } - - public void testGetObject(ResultSet resultSet, Map<String, Class<?>> map) throws SQLException { - try { - resultSet.getObject(ordinal, map); - fail("Was expecting to throw SQLDataException"); - } catch (Exception e) { - assertThat(e, isA((Class) SQLDataException.class)); // success - } - } - - public void testGetRef(ResultSet resultSet) throws SQLException { - try { - resultSet.getRef(ordinal); - fail("Was expecting to throw SQLDataException"); - } catch (Exception e) { - assertThat(e, isA((Class) SQLDataException.class)); // success - } - } - - public void testGetBlob(ResultSet resultSet) throws SQLException { - try { - resultSet.getBlob(ordinal); - fail("Was expecting to throw SQLDataException"); - } catch (Exception e) { - assertThat(e, isA((Class) SQLDataException.class)); // success - } - } - - public void testGetClob(ResultSet resultSet) throws SQLException { - try { - resultSet.getBlob(ordinal); - fail("Was expecting to throw SQLDataException"); - } catch (Exception e) { - assertThat(e, isA((Class) SQLDataException.class)); // success - } - } - - public void testGetArray(ResultSet resultSet) throws SQLException { - try { - resultSet.getArray(ordinal); - fail("Was expecting to throw SQLDataException"); - } catch (Exception e) { - assertThat(e, isA((Class) SQLDataException.class)); // success - } - } - - public void testGetDate(ResultSet resultSet, Calendar calendar) throws SQLException { - try { - resultSet.getDate(ordinal, calendar); - fail("Was expecting to throw SQLDataException"); - } catch (Exception e) { - assertThat(e, isA((Class) SQLDataException.class)); // success - } - } - - public void testGetTime(ResultSet resultSet, Calendar calendar) throws SQLException { - try { - resultSet.getTime(ordinal, calendar); - fail("Was expecting to throw SQLDataException"); - } catch (Exception e) { - assertThat(e, isA((Class) SQLDataException.class)); // success - } - } - - public void testGetTimestamp(ResultSet resultSet, Calendar calendar) throws SQLException { - try { - resultSet.getTimestamp(ordinal, calendar); - fail("Was expecting to throw SQLDataException"); - } catch (Exception e) { - assertThat(e, isA((Class) SQLDataException.class)); // success - } - } - - public void getURL(ResultSet resultSet) throws SQLException { - try { - resultSet.getURL(ordinal); - fail("Was expecting to throw SQLDataException"); - } catch (Exception e) { - assertThat(e, isA((Class) SQLDataException.class)); // success - } - } - - public void testGetNClob(ResultSet resultSet) throws SQLException { - try { - resultSet.getNClob(ordinal); - fail("Was expecting to throw SQLDataException"); - } catch (Exception e) { - assertThat(e, isA((Class) SQLDataException.class)); // success - } - } - - public void testGetSQLXML(ResultSet resultSet) throws SQLException { - try { - resultSet.getSQLXML(ordinal); - fail("Was expecting to throw SQLDataException"); - } catch (Exception e) { - assertThat(e, isA((Class) SQLDataException.class)); // success - } - } - - public void testGetNString(ResultSet resultSet) throws SQLException { - try { - resultSet.getNString(ordinal); - fail("Was expecting to throw SQLDataException"); - } catch (Exception e) { - assertThat(e, isA((Class) SQLDataException.class)); // success - } - } - - public void testGetNCharacterStream(ResultSet resultSet) throws SQLException { - try { - resultSet.getNCharacterStream(ordinal); - fail("Was expecting to throw SQLDataException"); - } catch (Exception e) { - assertThat(e, isA((Class) SQLDataException.class)); // success - } - } - } - - /** - * accessor test helper for the boolean column - */ - private static final class BooleanAccesorTestHelper extends AccessorTestHelper { - private BooleanAccesorTestHelper(int ordinal) { - super(ordinal); - } - - @Override public void testGetString(ResultSet resultSet) throws SQLException { - assertEquals("true", resultSet.getString(ordinal)); - } - - @Override public void testGetBoolean(ResultSet resultSet) throws SQLException { - assertEquals(true, resultSet.getBoolean(ordinal)); - } - - @Override public void testGetByte(ResultSet resultSet) throws SQLException { - assertEquals((byte) 1, resultSet.getByte(ordinal)); - } - - @Override public void testGetShort(ResultSet resultSet) throws SQLException { - assertEquals((short) 1, resultSet.getShort(ordinal)); - } - - @Override public void testGetInt(ResultSet resultSet) throws SQLException { - assertEquals(1, resultSet.getInt(ordinal)); - } - - @Override public void testGetLong(ResultSet resultSet) throws SQLException { - assertEquals(1L, resultSet.getLong(ordinal)); - } - - @Override public void testGetDecimal(ResultSet resultSet) throws SQLException { - assertEquals(BigDecimal.ONE, resultSet.getBigDecimal(ordinal)); - } - - @Override public void testGetFloat(ResultSet resultSet) throws SQLException { - assertEquals(1.0f, resultSet.getFloat(ordinal), 0); - } - - @Override public void testGetDouble(ResultSet resultSet) throws SQLException { - assertEquals(1.0d, resultSet.getDouble(ordinal), 0); - } - } - - /** - * accessor test helper for the byte column - */ - private static final class ByteAccesorTestHelper extends AccessorTestHelper { - private ByteAccesorTestHelper(int ordinal) { - super(ordinal); - } - - @Override public void testGetString(ResultSet resultSet) throws SQLException { - assertEquals("1", resultSet.getString(ordinal)); - } - - @Override public void testGetBoolean(ResultSet resultSet) throws SQLException { - assertEquals(true, resultSet.getBoolean(ordinal)); - } - - @Override public void testGetByte(ResultSet resultSet) throws SQLException { - assertEquals((byte) 1, resultSet.getByte(ordinal)); - } - - @Override public void testGetShort(ResultSet resultSet) throws SQLException { - assertEquals((short) 1, resultSet.getShort(ordinal)); - } - - @Override public void testGetInt(ResultSet resultSet) throws SQLException { - assertEquals(1, resultSet.getInt(ordinal)); - } - - @Override public void testGetLong(ResultSet resultSet) throws SQLException { - assertEquals(1L, resultSet.getLong(ordinal)); - } - - @Override public void testGetDecimal(ResultSet resultSet) throws SQLException { - assertEquals(BigDecimal.ONE, resultSet.getBigDecimal(ordinal)); - } - - @Override public void testGetFloat(ResultSet resultSet) throws SQLException { - assertEquals(1.0f, resultSet.getFloat(ordinal), 0); - } - - @Override public void testGetDouble(ResultSet resultSet) throws SQLException { - assertEquals(1.0d, resultSet.getDouble(ordinal), 0); - } - } - - /** - * accessor test helper for the short column - */ - private static final class ShortAccessorTestHelper extends AccessorTestHelper { - private ShortAccessorTestHelper(int ordinal) { - super(ordinal); - } - - @Override public void testGetString(ResultSet resultSet) throws SQLException { - assertEquals("2", resultSet.getString(ordinal)); - } - - @Override public void testGetBoolean(ResultSet resultSet) throws SQLException { - assertEquals(true, resultSet.getBoolean(ordinal)); - } - - @Override public void testGetByte(ResultSet resultSet) throws SQLException { - assertEquals((byte) 2, resultSet.getByte(ordinal)); - } - - @Override public void testGetShort(ResultSet resultSet) throws SQLException { - assertEquals((short) 2, resultSet.getShort(ordinal)); - } - - @Override public void testGetInt(ResultSet resultSet) throws SQLException { - assertEquals(2, resultSet.getInt(ordinal)); - } - - @Override public void testGetLong(ResultSet resultSet) throws SQLException { - assertEquals(2L, resultSet.getLong(ordinal)); - } - - @Override public void testGetDecimal(ResultSet resultSet) throws SQLException { - assertEquals(new BigDecimal(2), resultSet.getBigDecimal(ordinal)); - } - - @Override public void testGetFloat(ResultSet resultSet) throws SQLException { - assertEquals(2.0f, resultSet.getFloat(ordinal), 0); - } - - @Override public void testGetDouble(ResultSet resultSet) throws SQLException { - assertEquals(2.0d, resultSet.getDouble(ordinal), 0); - } - } - - /** - * accessor test helper for the int column - */ - private static final class IntAccessorTestHelper extends AccessorTestHelper { - private IntAccessorTestHelper(int ordinal) { - super(ordinal); - } - - @Override public void testGetString(ResultSet resultSet) throws SQLException { - assertEquals("3", resultSet.getString(ordinal)); - } - - @Override public void testGetBoolean(ResultSet resultSet) throws SQLException { - assertEquals(true, resultSet.getBoolean(ordinal)); - } - - @Override public void testGetByte(ResultSet resultSet) throws SQLException { - assertEquals((byte) 3, resultSet.getByte(ordinal)); - } - - @Override public void testGetShort(ResultSet resultSet) throws SQLException { - assertEquals((short) 3, resultSet.getShort(ordinal)); - } - - @Override public void testGetInt(ResultSet resultSet) throws SQLException { - assertEquals(3, resultSet.getInt(ordinal)); - } - - @Override public void testGetLong(ResultSet resultSet) throws SQLException { - assertEquals(3L, resultSet.getLong(ordinal)); - } - - @Override public void testGetDecimal(ResultSet resultSet) throws SQLException { - assertEquals(new BigDecimal(3), resultSet.getBigDecimal(ordinal)); - } - - @Override public void testGetFloat(ResultSet resultSet) throws SQLException { - assertEquals(3.0f, resultSet.getFloat(ordinal), 0); - } - - @Override public void testGetDouble(ResultSet resultSet) throws SQLException { - assertEquals(3.0d, resultSet.getDouble(ordinal), 0); - } - } - - /** - * accessor test helper for the long column - */ - private static final class LongAccessorTestHelper extends AccessorTestHelper { - private LongAccessorTestHelper(int ordinal) { - super(ordinal); - } - - @Override public void testGetString(ResultSet resultSet) throws SQLException { - assertEquals("4", resultSet.getString(ordinal)); - } - - @Override public void testGetBoolean(ResultSet resultSet) throws SQLException { - assertEquals(true, resultSet.getBoolean(ordinal)); - } - - @Override public void testGetByte(ResultSet resultSet) throws SQLException { - assertEquals((byte) 4, resultSet.getByte(ordinal)); - } - - @Override public void testGetShort(ResultSet resultSet) throws SQLException { - assertEquals((short) 4, resultSet.getShort(ordinal)); - } - - @Override public void testGetInt(ResultSet resultSet) throws SQLException { - assertEquals(4, resultSet.getInt(ordinal)); - } - - @Override public void testGetLong(ResultSet resultSet) throws SQLException { - assertEquals(4L, resultSet.getLong(ordinal)); - } - - @Override public void testGetDecimal(ResultSet resultSet) throws SQLException { - assertEquals(new BigDecimal(4), resultSet.getBigDecimal(ordinal)); - } - - @Override public void testGetFloat(ResultSet resultSet) throws SQLException { - assertEquals(4.0f, resultSet.getFloat(ordinal), 0); - } - - @Override public void testGetDouble(ResultSet resultSet) throws SQLException { - assertEquals(4.0d, resultSet.getDouble(ordinal), 0); - } - } - - /** - * accessor test helper for the float column - */ - private static final class FloatAccessorTestHelper extends AccessorTestHelper { - private FloatAccessorTestHelper(int ordinal) { - super(ordinal); - } - - @Override public void testGetString(ResultSet resultSet) throws SQLException { - assertEquals("5.0", resultSet.getString(ordinal)); - } - - @Override public void testGetBoolean(ResultSet resultSet) throws SQLException { - assertEquals(true, resultSet.getBoolean(ordinal)); - } - - @Override public void testGetByte(ResultSet resultSet) throws SQLException { - assertEquals((byte) 5, resultSet.getByte(ordinal)); - } - - @Override public void testGetShort(ResultSet resultSet) throws SQLException { - assertEquals((short) 5, resultSet.getShort(ordinal)); - } - - @Override public void testGetInt(ResultSet resultSet) throws SQLException { - assertEquals(5, resultSet.getInt(ordinal)); - } - - @Override public void testGetLong(ResultSet resultSet) throws SQLException { - assertEquals(5L, resultSet.getLong(ordinal)); - } - - @Override public void testGetDecimal(ResultSet resultSet) throws SQLException { - assertEquals(new BigDecimal(5).setScale(1), resultSet.getBigDecimal(ordinal)); - } - - @Override public void testGetFloat(ResultSet resultSet) throws SQLException { - assertEquals(5.0f, resultSet.getFloat(ordinal), 0); - } - - @Override public void testGetDouble(ResultSet resultSet) throws SQLException { - assertEquals(5.0d, resultSet.getDouble(ordinal), 0); - } - } - - /** - * accessor test helper for the double column - */ - private static final class DoubleAccessorTestHelper extends AccessorTestHelper { - private DoubleAccessorTestHelper(int ordinal) { - super(ordinal); - } - - @Override public void testGetString(ResultSet resultSet) throws SQLException { - assertEquals("6.0", resultSet.getString(ordinal)); - } - - @Override public void testGetBoolean(ResultSet resultSet) throws SQLException { - assertEquals(true, resultSet.getBoolean(ordinal)); - } - - @Override public void testGetByte(ResultSet resultSet) throws SQLException { - assertEquals((byte) 6, resultSet.getByte(ordinal)); - } - - @Override public void testGetShort(ResultSet resultSet) throws SQLException { - assertEquals((short) 6, resultSet.getShort(ordinal)); - } - - @Override public void testGetInt(ResultSet resultSet) throws SQLException { - assertEquals(6, resultSet.getInt(ordinal)); - } - - @Override public void testGetLong(ResultSet resultSet) throws SQLException { - assertEquals(6L, resultSet.getLong(ordinal)); - } - - @Override public void testGetDecimal(ResultSet resultSet) throws SQLException { - assertEquals(new BigDecimal(6).setScale(1), resultSet.getBigDecimal(ordinal)); - } - - @Override public void testGetFloat(ResultSet resultSet) throws SQLException { - assertEquals(6.0f, resultSet.getFloat(ordinal), 0); - } - - @Override public void testGetDouble(ResultSet resultSet) throws SQLException { - assertEquals(6.0d, resultSet.getDouble(ordinal), 0); - } - } - - /** - * accessor test helper for the date column - */ - private static final class DateAccessorTestHelper extends AccessorTestHelper { - private DateAccessorTestHelper(int ordinal) { - super(ordinal); - } - - @Override public void testGetString(ResultSet resultSet) throws SQLException { - assertEquals("2016-10-10", resultSet.getString(ordinal)); - } - - @Override public void testGetBoolean(ResultSet resultSet) throws SQLException { - assertEquals(true, resultSet.getBoolean(ordinal)); - } - - @Override public void testGetByte(ResultSet resultSet) throws SQLException { - assertEquals((byte) -68, resultSet.getByte(ordinal)); - } - - @Override public void testGetShort(ResultSet resultSet) throws SQLException { - assertEquals((short) 17084, resultSet.getShort(ordinal)); - } - - @Override public void testGetInt(ResultSet resultSet) throws SQLException { - assertEquals(17084, resultSet.getInt(ordinal)); - } - - @Override public void testGetLong(ResultSet resultSet) throws SQLException { - assertEquals(17084, resultSet.getLong(ordinal)); - } - - @Override public void testGetDate(ResultSet resultSet, Calendar calendar) throws SQLException { - assertEquals(new Date(1476130718123L), resultSet.getDate(ordinal, calendar)); - } - } - - /** - * accessor test helper for the time column - */ - private static final class TimeAccessorTestHelper extends AccessorTestHelper { - private TimeAccessorTestHelper(int ordinal) { - super(ordinal); - } - - @Override public void testGetString(ResultSet resultSet) throws SQLException { - assertEquals("20:18:38", resultSet.getString(ordinal)); - } - - @Override public void testGetBoolean(ResultSet resultSet) throws SQLException { - assertEquals(true, resultSet.getBoolean(ordinal)); - } - - @Override public void testGetByte(ResultSet resultSet) throws SQLException { - assertEquals((byte) -85, resultSet.getByte(ordinal)); - } - - @Override public void testGetShort(ResultSet resultSet) throws SQLException { - assertEquals((short) -20053, resultSet.getShort(ordinal)); - } - - @Override public void testGetInt(ResultSet resultSet) throws SQLException { - assertEquals(73118123, resultSet.getInt(ordinal)); - } - - @Override public void testGetLong(ResultSet resultSet) throws SQLException { - assertEquals(73118123, resultSet.getLong(ordinal)); - } - - @Override public void testGetTime(ResultSet resultSet, Calendar calendar) throws SQLException { - assertEquals(new Time(1476130718123L), resultSet.getTime(ordinal, calendar)); - } - } - - /** - * accessor test helper for the timestamp column - */ - private static final class TimestampAccessorTestHelper extends AccessorTestHelper { - private TimestampAccessorTestHelper(int ordinal) { - super(ordinal); - } - - @Override public void testGetString(ResultSet resultSet) throws SQLException { - assertEquals("2016-10-10 20:18:38", resultSet.getString(ordinal)); - } - - @Override public void testGetBoolean(ResultSet resultSet) throws SQLException { - assertEquals(true, resultSet.getBoolean(ordinal)); - } - - @Override public void testGetByte(ResultSet resultSet) throws SQLException { - assertEquals((byte) -85, resultSet.getByte(ordinal)); - } - - @Override public void testGetShort(ResultSet resultSet) throws SQLException { - assertEquals((short) 16811, resultSet.getShort(ordinal)); - } - - @Override public void testGetInt(ResultSet resultSet) throws SQLException { - assertEquals(-1338031701, resultSet.getInt(ordinal)); - } - - @Override public void testGetLong(ResultSet resultSet) throws SQLException { - assertEquals(1476130718123L, resultSet.getLong(ordinal)); - } - - @Override public void testGetDate(ResultSet resultSet, Calendar calendar) throws SQLException { - assertEquals(new Date(1476130718123L), resultSet.getDate(ordinal, calendar)); - } - - @Override public void testGetTime(ResultSet resultSet, Calendar calendar) throws SQLException { - // how come both are different? DST... - //assertEquals(new Time(1476130718123L), resultSet.getTime(ordinal, calendar)); - assertEquals(new Time(73118123L), resultSet.getTime(ordinal, calendar)); - } - - @Override public void testGetTimestamp(ResultSet resultSet, Calendar calendar) - throws SQLException { - assertEquals(new Timestamp(1476130718123L), resultSet.getTimestamp(ordinal, calendar)); - } - } - - /** - * accessor test helper for the string column - */ - private static final class StringAccessorTestHelper extends AccessorTestHelper { - private StringAccessorTestHelper(int ordinal) { - super(ordinal); - } - - @Override public void testGetString(ResultSet resultSet) throws SQLException { - assertEquals("testvalue", resultSet.getString(ordinal)); - } - } - - private static final Calendar DEFAULT_CALENDAR = DateTimeUtils.calendar(); - - private static Connection connection = null; - private static ResultSet resultSet = null; - - @BeforeClass - public static void executeQuery() throws SQLException { - Properties properties = new Properties(); - properties.setProperty("timeZone", "GMT"); - - connection = new TestDriver().connect("jdbc:test", properties); - resultSet = connection.createStatement().executeQuery("SELECT * FROM TABLE"); - resultSet.next(); // move to the first record - } - - @AfterClass - public static void cleanupQuery() throws SQLException { - if (resultSet != null) { - resultSet.close(); - } - - if (connection != null) { - connection.close(); - } - } - - @Parameters - public static Collection<AccessorTestHelper> data() { - return Arrays.<AccessorTestHelper>asList( - new BooleanAccesorTestHelper(1), - new ByteAccesorTestHelper(2), - new ShortAccessorTestHelper(3), - new IntAccessorTestHelper(4), - new LongAccessorTestHelper(5), - new FloatAccessorTestHelper(6), - new DoubleAccessorTestHelper(7), - new StringAccessorTestHelper(8), - new DateAccessorTestHelper(9), - new TimeAccessorTestHelper(10), - new TimestampAccessorTestHelper(11)); - } - - private final AccessorTestHelper testHelper; - - public AvaticaResultSetConversionsTest(AccessorTestHelper testHelper) { - this.testHelper = testHelper; - } - - @Test - public void testGetString() throws SQLException { - testHelper.testGetString(resultSet); - } - - @Test - public void testGetBoolean() throws SQLException { - testHelper.testGetBoolean(resultSet); - } - - @Test - public void testGetByte() throws SQLException { - testHelper.testGetByte(resultSet); - } - - @Test - public void testGetShort() throws SQLException { - testHelper.testGetShort(resultSet); - } - - @Test - public void testGetInt() throws SQLException { - testHelper.testGetInt(resultSet); - } - - @Test - public void testGetLong() throws SQLException { - testHelper.testGetLong(resultSet); - } - - @Test - public void testGetFloat() throws SQLException { - testHelper.testGetFloat(resultSet); - } - - @Test - public void testGetDouble() throws SQLException { - testHelper.testGetDouble(resultSet); - } - - @Test - public void testGetDecimal() throws SQLException { - testHelper.testGetDecimal(resultSet); - } - - @Test - public void testGetBytes() throws SQLException { - testHelper.testGetBytes(resultSet); - } - - @Test - public void testGetAsciiStream() throws SQLException { - testHelper.testGetAsciiStream(resultSet); - } - - @Test - public void testGetBinaryStream() throws SQLException { - testHelper.testGetBinaryStream(resultSet); - } - - @Test - public void testGetObject() throws SQLException { - testHelper.testGetObject(resultSet); - } - - @Test - public void testGetCharacterStream() throws SQLException { - testHelper.testGetCharacterStream(resultSet); - } - - @Test - public void testGetObjectWithMap() throws SQLException { - testHelper.testGetObject(resultSet, Collections.<String, Class<?>>emptyMap()); - } - - @Test - public void testGetRef() throws SQLException { - testHelper.testGetRef(resultSet); - } - - @Test - public void testGetBlob() throws SQLException { - testHelper.testGetBlob(resultSet); - } - - @Test - public void testGetClob() throws SQLException { - testHelper.testGetClob(resultSet); - } - - @Test - public void testGetArray() throws SQLException { - testHelper.testGetArray(resultSet); - } - - @Test - public void testGetDate() throws SQLException { - testHelper.testGetDate(resultSet, DEFAULT_CALENDAR); - } - - @Test - public void testGetTime() throws SQLException { - testHelper.testGetTime(resultSet, DEFAULT_CALENDAR); - } - - @Test - public void testGetTimestamp() throws SQLException { - testHelper.testGetTimestamp(resultSet, DEFAULT_CALENDAR); - } - - @Test - public void getURL() throws SQLException { - testHelper.getURL(resultSet); - } - - @Test - public void testGetNClob() throws SQLException { - testHelper.testGetNClob(resultSet); - } - - @Test - public void testGetSQLXML() throws SQLException { - testHelper.testGetSQLXML(resultSet); - } - - @Test - public void testGetNString() throws SQLException { - testHelper.testGetNString(resultSet); - } - - @Test - public void testGetNCharacterStream() throws SQLException { - testHelper.testGetNCharacterStream(resultSet); - } -} - -// End AvaticaResultSetConversionsTest.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/core/src/test/java/org/apache/calcite/avatica/AvaticaStatementTest.java ---------------------------------------------------------------------- diff --git a/avatica/core/src/test/java/org/apache/calcite/avatica/AvaticaStatementTest.java b/avatica/core/src/test/java/org/apache/calcite/avatica/AvaticaStatementTest.java deleted file mode 100644 index 5f6b56a..0000000 --- a/avatica/core/src/test/java/org/apache/calcite/avatica/AvaticaStatementTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.calcite.avatica; - -import org.junit.Before; -import org.junit.Test; - -import java.sql.SQLException; - -import static org.junit.Assert.assertArrayEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -/** - * Test class for AvaticaStatement - */ -public class AvaticaStatementTest { - - private AvaticaStatement statement; - - @Before public void setup() { - statement = mock(AvaticaStatement.class); - } - - @Test public void testUpdateCounts() throws SQLException { - long[] longValues = new long[] {-1, -3, 1, 5, ((long) Integer.MAX_VALUE) + 1}; - int[] intValues = new int[] {-1, -3, 1, 5, Integer.MAX_VALUE}; - when(statement.executeBatch()).thenCallRealMethod(); - when(statement.executeLargeBatch()).thenCallRealMethod(); - when(statement.executeBatchInternal()).thenReturn(longValues); - - assertArrayEquals(intValues, statement.executeBatch()); - assertArrayEquals(longValues, statement.executeLargeBatch()); - } -} - -// End AvaticaStatementTest.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/core/src/test/java/org/apache/calcite/avatica/ConnectionConfigImplTest.java ---------------------------------------------------------------------- diff --git a/avatica/core/src/test/java/org/apache/calcite/avatica/ConnectionConfigImplTest.java b/avatica/core/src/test/java/org/apache/calcite/avatica/ConnectionConfigImplTest.java deleted file mode 100644 index bbe30e1..0000000 --- a/avatica/core/src/test/java/org/apache/calcite/avatica/ConnectionConfigImplTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.calcite.avatica; - -import org.junit.Test; - -import java.util.Properties; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -/** - * Test class for {@link ConnectionConfigImpl}. - */ -public class ConnectionConfigImplTest { - - @Test public void testTrustStore() { - final String truststore = "/my/truststore.jks"; - final String pw = "supremelysecret"; - Properties props = new Properties(); - props.setProperty(BuiltInConnectionProperty.TRUSTSTORE.name(), truststore); - props.setProperty(BuiltInConnectionProperty.TRUSTSTORE_PASSWORD.name(), pw); - ConnectionConfigImpl config = new ConnectionConfigImpl(props); - assertEquals(truststore, config.truststore().getAbsolutePath()); - assertEquals(pw, config.truststorePassword()); - } - - @Test public void testNoTruststore() { - Properties props = new Properties(); - ConnectionConfigImpl config = new ConnectionConfigImpl(props); - assertNull(config.truststore()); - assertNull(config.truststorePassword()); - } -} - -// End ConnectionConfigImplTest.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/core/src/test/java/org/apache/calcite/avatica/FrameTest.java ---------------------------------------------------------------------- diff --git a/avatica/core/src/test/java/org/apache/calcite/avatica/FrameTest.java b/avatica/core/src/test/java/org/apache/calcite/avatica/FrameTest.java deleted file mode 100644 index e17bf92..0000000 --- a/avatica/core/src/test/java/org/apache/calcite/avatica/FrameTest.java +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.calcite.avatica; - -import org.apache.calcite.avatica.Meta.Frame; -import org.apache.calcite.avatica.proto.Common; -import org.apache.calcite.avatica.proto.Common.ColumnValue; -import org.apache.calcite.avatica.proto.Common.TypedValue; - -import org.junit.Test; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Date; -import java.util.Iterator; -import java.util.List; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -/** - * Tests serialization of {@link Frame}. - */ -public class FrameTest { - - private static final TypedValue NUMBER_VALUE = TypedValue.newBuilder().setNumberValue(1) - .setType(Common.Rep.LONG).build(); - - private void serializeAndTestEquality(Frame frame) { - Frame frameCopy = Frame.fromProto(frame.toProto()); - - assertEquals(frame.done, frameCopy.done); - assertEquals(frame.offset, frameCopy.offset); - - Iterable<Object> origRows = frame.rows; - Iterable<Object> copiedRows = frameCopy.rows; - - assertEquals("Expected rows to both be null, or both be non-null", - origRows == null, copiedRows == null); - - Iterator<Object> origIter = origRows.iterator(); - Iterator<Object> copiedIter = copiedRows.iterator(); - while (origIter.hasNext() && copiedIter.hasNext()) { - Object orig = origIter.next(); - Object copy = copiedIter.next(); - - assertEquals(orig == null, copy == null); - - // This is goofy, but it seems like an Array comes from the JDBC implementation but then - // the resulting Frame has a List to support the Avatica typed Accessors - assertEquals(Object[].class, orig.getClass()); - assertTrue("Expected List but got " + copy.getClass(), copy instanceof List); - - @SuppressWarnings("unchecked") - List<Object> copyList = (List<Object>) copy; - - assertArrayEquals((Object[]) orig, copyList.toArray(new Object[0])); - } - - assertEquals(origIter.hasNext(), copiedIter.hasNext()); - } - - @Test - public void testEmpty() { - serializeAndTestEquality(Frame.EMPTY); - } - - @Test - public void testSingleRow() { - ArrayList<Object> rows = new ArrayList<>(); - rows.add(new Object[] {"string", Integer.MAX_VALUE, new Date().getTime()}); - - Frame singleRow = new Frame(0, true, rows); - - serializeAndTestEquality(singleRow); - } - - @Test - public void testMultipleRows() { - ArrayList<Object> rows = new ArrayList<>(); - rows.add(new Object[] {"string", Integer.MAX_VALUE, new Date().getTime()}); - rows.add(new Object[] {"gnirts", 0, Long.MIN_VALUE}); - rows.add(new Object[] {"", null, Long.MAX_VALUE}); - - Frame singleRow = new Frame(0, true, rows); - - serializeAndTestEquality(singleRow); - } - - @Test public void testMalformedColumnValue() { - // Invalid ColumnValue: has an array and scalar - final ColumnValue bothAttributesColumnValue = ColumnValue.newBuilder().setHasArrayValue(true) - .setScalarValue(NUMBER_VALUE).build(); - // Note omission of setScalarValue(TypedValue). - final ColumnValue neitherAttributeColumnValue = ColumnValue.newBuilder().setHasArrayValue(false) - .build(); - - try { - Frame.validateColumnValue(bothAttributesColumnValue); - fail("Validating the ColumnValue should have failed as it has an array and scalar"); - } catch (IllegalArgumentException e) { - // Pass - } - - try { - Frame.validateColumnValue(neitherAttributeColumnValue); - fail("Validating the ColumnValue should have failed as it has neither an array nor scalar"); - } catch (IllegalArgumentException e) { - // Pass - } - } - - @Test public void testColumnValueBackwardsCompatibility() { - // 1 - final ColumnValue oldStyleScalarValue = ColumnValue.newBuilder().addValue(NUMBER_VALUE).build(); - // [1, 1] - final ColumnValue oldStyleArrayValue = ColumnValue.newBuilder().addValue(NUMBER_VALUE) - .addValue(NUMBER_VALUE).build(); - - assertFalse(Frame.isNewStyleColumn(oldStyleScalarValue)); - assertFalse(Frame.isNewStyleColumn(oldStyleArrayValue)); - - Object scalar = Frame.parseOldStyleColumn(oldStyleScalarValue); - assertEquals(1L, scalar); - - Object array = Frame.parseOldStyleColumn(oldStyleArrayValue); - assertEquals(Arrays.asList(1L, 1L), array); - } - - @Test public void testColumnValueParsing() { - // 1 - final ColumnValue scalarValue = ColumnValue.newBuilder().setScalarValue(NUMBER_VALUE).build(); - // [1, 1] - final ColumnValue arrayValue = ColumnValue.newBuilder().addArrayValue(NUMBER_VALUE) - .addArrayValue(NUMBER_VALUE).setHasArrayValue(true).build(); - - assertTrue(Frame.isNewStyleColumn(scalarValue)); - assertTrue(Frame.isNewStyleColumn(arrayValue)); - - Object scalar = Frame.parseColumn(scalarValue); - assertEquals(1L, scalar); - - Object array = Frame.parseColumn(arrayValue); - assertEquals(Arrays.asList(1L, 1L), array); - } - - @Test public void testDeprecatedValueAttributeForScalars() { - // Create a row with schema: [VARCHAR, INTEGER, DATE] - List<Object> rows = Collections.<Object>singletonList(new Object[] {"string", Integer.MAX_VALUE, - new Date().getTime()}); - Meta.Frame frame = Meta.Frame.create(0, true, rows); - // Convert it to a protobuf - Common.Frame protoFrame = frame.toProto(); - assertEquals(1, protoFrame.getRowsCount()); - // Get that row we created - Common.Row protoRow = protoFrame.getRows(0); - // One row has many columns - List<Common.ColumnValue> protoColumns = protoRow.getValueList(); - assertEquals(3, protoColumns.size()); - // Verify that the scalar value is also present in the deprecated values attributes. - List<Common.TypedValue> deprecatedValues = protoColumns.get(0).getValueList(); - assertEquals(1, deprecatedValues.size()); - Common.TypedValue scalarValue = protoColumns.get(0).getScalarValue(); - assertEquals(deprecatedValues.get(0), scalarValue); - } - - @Test public void testDeprecatedValueAttributeForArrays() { - // Create a row with schema: [VARCHAR, ARRAY] - List<Object> rows = Collections.<Object>singletonList(new Object[] {"string", - Arrays.asList(1, 2, 3)}); - Meta.Frame frame = Meta.Frame.create(0, true, rows); - // Convert it to a protobuf - Common.Frame protoFrame = frame.toProto(); - assertEquals(1, protoFrame.getRowsCount()); - // Get that row we created - Common.Row protoRow = protoFrame.getRows(0); - // One row has many columns - List<Common.ColumnValue> protoColumns = protoRow.getValueList(); - // We should have two columns - assertEquals(2, protoColumns.size()); - // Fetch the ARRAY column - Common.ColumnValue protoColumn = protoColumns.get(1); - // We should have the 3 ARRAY elements in the array_values attribute as well as the deprecated - // values attribute. - List<Common.TypedValue> deprecatedValues = protoColumn.getValueList(); - assertEquals(3, deprecatedValues.size()); - assertTrue("Column 2 should have an array_value", protoColumns.get(1).getHasArrayValue()); - List<Common.TypedValue> arrayValues = protoColumns.get(1).getArrayValueList(); - assertEquals(arrayValues, deprecatedValues); - } -} - -// End FrameTest.java
