You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/02/17 21:10:37 UTC

[GitHub] [arrow] westonpace commented on a change in pull request #11982: ARROW-15313: [C++][Java][FlightRPC] Implement type info method to flight-sql

westonpace commented on a change in pull request #11982:
URL: https://github.com/apache/arrow/pull/11982#discussion_r809469564



##########
File path: format/FlightSql.proto
##########
@@ -867,6 +867,167 @@ enum SqlSupportsConvert {
   SQL_CONVERT_VARCHAR = 19;
 }
 
+enum SqlDataType {
+  SQL_TYPE_UNKNOWN_TYPE = 0;
+  SQL_TYPE_CHAR = 1;
+  SQL_TYPE_NUMERIC = 2;
+  SQL_TYPE_DECIMAL = 3;
+  SQL_TYPE_INTEGER = 4;
+  SQL_TYPE_SMALLINT = 5;
+  SQL_TYPE_FLOAT = 6;
+  SQL_TYPE_REAL = 7;
+  SQL_TYPE_DOUBLE = 8;
+  SQL_TYPE_DATETIME = 9;
+  SQL_TYPE_INTERVAL = 10;
+  SQL_TYPE_VARCHAR = 12;
+}
+
+enum SqlDatetimeSubcode {
+  option allow_alias = true;
+  SQL_SUBCODE_UNKNOWN = 0;
+  SQL_SUBCODE_YEAR = 1;
+  SQL_SUBCODE_DATE = 1;
+  SQL_SUBCODE_TIME = 2;
+  SQL_SUBCODE_MONTH = 2;
+  SQL_SUBCODE_TIMESTAMP = 3;
+  SQL_SUBCODE_DAY = 3;
+  SQL_SUBCODE_TIME_WITH_TIMEZONE = 4;
+  SQL_SUBCODE_HOUR = 4;
+  SQL_SUBCODE_TIMESTAMP_WITH_TIMEZONE = 5;
+  SQL_SUBCODE_MINUTE = 5;
+  SQL_SUBCODE_SECOND = 6;
+  SQL_SUBCODE_YEAR_TO_MONTH = 7;
+  SQL_SUBCODE_DAY_TO_HOUR = 8;
+  SQL_SUBCODE_DAY_TO_MINUTE = 9;
+  SQL_SUBCODE_DAY_TO_SECOND = 10;
+  SQL_SUBCODE_HOUR_TO_MINUTE = 11;
+  SQL_SUBCODE_HOUR_TO_SECOND = 12;
+  SQL_SUBCODE_MINUTE_TO_SECOND = 13;
+  SQL_SUBCODE_INTERVAL_YEAR = 101;
+  SQL_SUBCODE_INTERVAL_MONTH = 102;
+  SQL_SUBCODE_INTERVAL_DAY = 103;
+  SQL_SUBCODE_INTERVAL_HOUR = 104;
+  SQL_SUBCODE_INTERVAL_MINUTE = 105;
+  SQL_SUBCODE_INTERVAL_SECOND = 106;
+  SQL_SUBCODE_INTERVAL_YEAR_TO_MONTH = 107;
+  SQL_SUBCODE_INTERVAL_DAY_TO_HOUR = 108;
+  SQL_SUBCODE_INTERVAL_DAY_TO_MINUTE = 109;
+  SQL_SUBCODE_INTERVAL_DAY_TO_SECOND = 110;
+  SQL_SUBCODE_INTERVAL_HOUR_TO_MINUTE = 111;
+  SQL_SUBCODE_INTERVAL_HOUR_TO_SECOND = 112;
+  SQL_SUBCODE_INTERVAL_MINUTE_TO_SECOND = 113;
+}
+
+enum Nullable {
+  /**
+   * Indicates that the fields does not allow the use of null values.
+   */
+  NULLABILITY_NO_NULLS = 0;
+
+  /**
+   * Indicates that the fields allow the use of null values.
+   */
+  NULLABILITY_NULLABLE = 1;
+
+  /**
+   * Indicates that nullability of the fields can not be determined.
+   */
+  NULLABILITY_UNKNOWN = 2;
+}
+
+enum Searchable {
+  /**
+   * Indicates that column can not be used in a WHERE clause.
+   */
+  SEARCHABLE_NONE = 0;
+
+  /**
+   * Indicates that the column can be used in a WHERE clause if it is using a
+   * LIKE predicate.
+   */
+  SEARCHABLE_CHAR = 1;
+
+  /**
+   * Indicates that the column can be used in a WHERE clause using other predicates
+   * except for LIKE.
+   *
+   * - Allowed operators: comparison, quantified comparison, BETWEEN,
+   *                      DISTINCT, IN, MATCH, and UNIQUE.
+   */
+  SEARCHABLE_BASIC = 2;
+
+  /**
+   * Indicates that the column can be used in a WHERE clause using any operator.
+   */
+  SEARCHABLE_FULL = 3;
+}
+
+/*
+ * Represents a request to retrieve information about data type supported on a Flight SQL enabled backend.
+ * Used in the command member of FlightDescriptor for the following RPC calls:
+ *  - GetSchema: return the schema of the query.
+ *  - GetFlightInfo: execute the catalog metadata request.
+ *
+ * The returned schema will be:
+ * <
+ *   type_name: utf8 not null (The name of the data type, for example: VARCHAR, INTEGER, etc),
+ *   data_type: int not null (The SQL data type),
+ *   column_size: int (The maximum size supported by that column.
+ *                     In case of numeric types, this represents the maximum precision.
+ *                     In case of string types, this represents the character length.
+ *                     In case of datetime data types, this represents the length in characters of the string representation.
+ *                     NULL is returned for data types where column size is not applicable.),
+ *   literal_prefix: utf8 (Character or characters used to prefix a literal, NULL is returned for
+ *                         data types where a literal prefix is not applicable.),
+ *   literal_suffix: utf8 (Character or characters used to terminate a literal,
+ *                         NULL is returned for data types where a literal suffix is not applicable.),
+ *   create_params: list<utf8 not null>
+ *                        (A list of keywords corresponding to which parameters can be used when creating
+ *                         a column for that specific type.
+ *                         NULL is returned if there are no parameters for the data type definition.),
+ *   nullable: int not null (Shows if the data type accepts a NULL value. The possible values can be seen in the
+ *                           Nullable enum.),
+ *   case_sensitive: bool not null (Shows if a character data type is case-sensitive in collations and comparisons),
+ *   searchable: int not null (Shows how the data type is used in a WHERE clause. The possible values can be seen in the
+ *                             Searchable enum.),
+ *   unsigned_attribute: bool (Shows if the data type is unsigned. NULL is returned if the attribute is
+ *                             not applicable to the data type or the data type is not numeric.),
+ *   fixed_prec_scale: bool not null (Shows if the data type has predefined fixed precision and scale.),

Review comment:
       There is also a slight difference in semantics when `fixed_prec_scale` is true.  `MONEY` can generally be thought of as a decimal with precision 19 and scale 4 but consider this example on SQL Server 2017...
   
   ```
   CREATE TABLE sample (mon MONEY, deci DECIMAL(10, 4));
   INSERT INTO sample (mon, deci) VALUES (1, 1);
   SELECT mon / 100000, deci / 100000 FROM sample;
   ```
   
   This will return:
   
   | mon / 100000 | deci / 100000 |
   | ------------- | ------------- |
   | 0  | 0.00001  |
   
   This is because (I believe) a data type with `fixed_prec_scale = false` is not allowed to be widened as a natural result of arithmetic operations.
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org