Skip to content

Commit

Permalink
DRILL-3216: Part 1--Pre-core code hygiene.
Browse files Browse the repository at this point in the history
Many-instance changes:  [DatabaseMetaDataGetColumnsTest]
- Renamed "...opt..." columns and methods to match "...mdrOpt" variables.
- Renamed "...req..." columns and methods to match "...mdrReq" variables.
- Renamed "testRow..." variables to "mdrUnk".
- Added/applied getIntOrNull(...) especially to simplify null cases.
- Put REAL, FLOAT, and DOUBLE in that order (smallest, ~variable, largest).
- (Edited "nullability code" -> "nullability code:".)

Renamed "type" -> "relDataType"; "sqlType" -> "sqlTypeName".
Changed "dfs_test.tmp" -> VIEW_SCHEMA.
Re-aligned query SQL.
Added 2 "final".
Edited 3253 (test plugin) TODOs.
Purged several comments.
Wrapped some lines.
  • Loading branch information
dsbos authored and parthchandra committed Jun 17, 2015
1 parent 71082e6 commit b018234
Show file tree
Hide file tree
Showing 3 changed files with 581 additions and 726 deletions.
Expand Up @@ -59,35 +59,35 @@ public Column(String catalog, String schemaName, String tableName, RelDataTypeFi
this.TABLE_NAME = tableName;

this.COLUMN_NAME = field.getName();
RelDataType type = field.getType();
SqlTypeName sqlType = type.getSqlTypeName();
final RelDataType relDataType = field.getType();
final SqlTypeName sqlTypeName = relDataType.getSqlTypeName();

this.ORDINAL_POSITION = field.getIndex();
this.IS_NULLABLE = type.isNullable() ? "YES" : "NO";
this.IS_NULLABLE = relDataType.isNullable() ? "YES" : "NO";

if (sqlType == SqlTypeName.ARRAY || sqlType == SqlTypeName.MAP || sqlType == SqlTypeName.ROW) {
if (sqlTypeName == SqlTypeName.ARRAY || sqlTypeName == SqlTypeName.MAP || sqlTypeName == SqlTypeName.ROW) {
// For complex types use SqlTypeName's toString method to display the
// inside elements.
String typeString = type.toString();
String typeString = relDataType.toString();

// RelDataType.toString prints "RecordType" for "STRUCT".
this.DATA_TYPE = type.toString().replace("RecordType", "STRUCT");
this.DATA_TYPE = relDataType.toString().replace("RecordType", "STRUCT");
} else {
this.DATA_TYPE = sqlType.toString();
this.DATA_TYPE = sqlTypeName.toString();
}

this.NUMERIC_PRECISION_RADIX = (sqlType == SqlTypeName.DECIMAL) ? 10 : -1; // TODO: where do we get radix?
this.NUMERIC_PRECISION_RADIX = (sqlTypeName == SqlTypeName.DECIMAL) ? 10 : -1; // TODO: where do we get radix?

if (sqlType == SqlTypeName.VARCHAR) {
if (sqlTypeName == SqlTypeName.VARCHAR) {
// Max length is stored as precision in Optiq.
this.CHARACTER_MAXIMUM_LENGTH = (sqlType.allowsPrec()) ? type.getPrecision() : -1;
this.CHARACTER_MAXIMUM_LENGTH = (sqlTypeName.allowsPrec()) ? relDataType.getPrecision() : -1;
this.NUMERIC_PRECISION = -1;
} else {
this.CHARACTER_MAXIMUM_LENGTH = -1;
this.NUMERIC_PRECISION = (sqlType.allowsPrec()) ? type.getPrecision() : -1;
this.NUMERIC_PRECISION = (sqlTypeName.allowsPrec()) ? relDataType.getPrecision() : -1;
}

this.NUMERIC_SCALE = (sqlType.allowsScale())?type.getScale(): -1;
this.NUMERIC_SCALE = (sqlTypeName.allowsScale())?relDataType.getScale(): -1;
}
}

Expand Down
20 changes: 11 additions & 9 deletions exec/jdbc/src/main/java/org/apache/drill/jdbc/impl/MetaImpl.java
Expand Up @@ -57,21 +57,23 @@ class MetaImpl implements Meta {
/** (Maximum) precision of BIGINT. */
private static final int PREC_BIGINT = 19;

/** Precision of REAL. */
// TEMPORARY partial change (corrected to 7 in Part 2):
private static final int PREC_REAL = 15;
/** Precision of FLOAT. */
private static final int PREC_FLOAT = 7;
/** Precision of DOUBLE. */
private static final int PREC_DOUBLE = 15;
/** Precision of REAL. */
private static final int PREC_REAL = PREC_DOUBLE;

/** Scale of INTEGER types. */
private static final int SCALE_INTEGRAL = 0;
// TEMPORARY partial change (corrected to 7 in Part 2):
/** JDBC conventional(?) scale value for REAL. */
private static final int SCALE_REAL = 15;
/** JDBC conventional(?) scale value for FLOAT. */
private static final int SCALE_FLOAT = 7;
/** JDBC conventional(?) scale value for DOUBLE. */
private static final int SCALE_DOUBLE = 15;
/** JDBC conventional(?) scale value for REAL. */
private static final int SCALE_REAL = SCALE_DOUBLE;

/** (Apparent) maximum precision for starting unit of INTERVAL type. */
private static final int PREC_INTERVAL_LEAD_MAX = 10;
Expand Down Expand Up @@ -360,9 +362,9 @@ public ResultSet getColumns(String catalog, Pat schemaPattern,
// NUM_PREC_RADIX coordinated)? INFORMATION_SCHEMA.COLUMNS's value
// are supposed to be in bits (per the SQL spec.). What does JDBC
// require and allow?
+ "\n WHEN 'REAL' THEN " + PREC_REAL
+ "\n WHEN 'FLOAT' THEN " + PREC_FLOAT
+ "\n WHEN 'DOUBLE' THEN " + PREC_DOUBLE
+ "\n WHEN 'REAL' THEN " + PREC_REAL

// "For character data, ... the length in characters":
// TODO: BUG: DRILL-2459: For CHARACTER / CHAR, length is not in
Expand Down Expand Up @@ -430,9 +432,9 @@ public ResultSet getColumns(String catalog, Pat schemaPattern,
+ "\n 'BIGINT' THEN " + SCALE_INTEGRAL
+ "\n WHEN 'DECIMAL', "
+ "\n 'NUMERIC' THEN NUMERIC_SCALE "
+ "\n WHEN 'REAL' THEN " + SCALE_REAL
+ "\n WHEN 'FLOAT' THEN " + SCALE_FLOAT
+ "\n WHEN 'DOUBLE' THEN " + SCALE_DOUBLE
+ "\n WHEN 'REAL' THEN " + SCALE_REAL
+ "\n WHEN 'INTERVAL' THEN NUMERIC_SCALE "
+ "\n WHEN 'INTERVAL_YEAR_MONTH' THEN 0 "
+ "\n WHEN 'INTERVAL_DAY_TIME' THEN NUMERIC_SCALE "
Expand All @@ -446,9 +448,9 @@ public ResultSet getColumns(String catalog, Pat schemaPattern,
+ "\n 'BIGINT' THEN " + RADIX_INTEGRAL
+ "\n WHEN 'DECIMAL', "
+ "\n 'NUMERIC' THEN " + RADIX_DECIMAL
+ "\n WHEN 'FLOAT', "
+ "\n 'DOUBLE', "
+ "\n 'REAL' THEN " + RADIX_APPROXIMATE
+ "\n WHEN 'REAL', "
+ "\n 'FLOAT', "
+ "\n 'DOUBLE' THEN " + RADIX_APPROXIMATE
+ "\n WHEN 'INTERVAL_YEAR_MONTH', "
+ "\n 'INTERVAL_DAY_TIME' THEN " + RADIX_INTERVAL
+ "\n ELSE NULL"
Expand Down

0 comments on commit b018234

Please sign in to comment.