Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix database schema generation w.r.t. #4268 for additional databases #4564

Merged
merged 6 commits into from
Nov 21, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public String getURL(String hostname, String port, String databaseName) {

@Override
public String getExtraOptionsHelpText() {
return "https://cloud.google.com/bigquery/partners/simba-drivers/";
return "https://cloud.google.com/bigquery/docs/reference/odbc-jdbc-drivers";
}

@Override
Expand Down Expand Up @@ -89,14 +89,20 @@ public String getFieldDefinition(
break;

case IValueMeta.TYPE_NUMBER, IValueMeta.TYPE_INTEGER, IValueMeta.TYPE_BIGNUMBER:
if (precision == 0) {
if (type == IValueMeta.TYPE_INTEGER) {
// Integer values...
retval += "INT64";
} else if (type == IValueMeta.TYPE_BIGNUMBER) {
// Fixed point value...
if (v.getLength() < 39) {
retval += "NUMERIC";
} else {
retval += "BIGNUMERIC";
}
} else {
// Floating point value with double precision...
retval += "FLOAT64";
}
if (fieldname.equalsIgnoreCase(tk) || fieldname.equalsIgnoreCase(pk)) {
retval += " NOT NULL";
}
break;

case IValueMeta.TYPE_STRING:
Expand All @@ -112,6 +118,10 @@ public String getFieldDefinition(
break;
}

if (fieldname.equalsIgnoreCase(tk) || fieldname.equalsIgnoreCase(pk)) {
retval += " NOT NULL";
}

if (addCr) {
retval += Const.CR;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public String getURL(String hostname, String port, String databaseName) {
}

/**
* Checks whether or not the command setFetchSize() is supported by the JDBC driver...
* Checks whether the command setFetchSize() is supported by the JDBC driver...
*
* @return true is setFetchSize() is supported!
*/
Expand Down Expand Up @@ -179,27 +179,35 @@ public String getFieldDefinition(
) {
retval += "IDENTITY";
} else {
if (length > 0) {
if (precision > 0 || length > 18) {
retval += "DECIMAL(" + length + ", " + precision + ")";
if (type == IValueMeta.TYPE_INTEGER) {
// Integer values...
if (length < 3) {
retval += "TINYINT";
} else if (length < 5) {
retval += "SMALLINT";
} else if (length < 10) {
retval += "INT";
} else if (length < 20) {
retval += "BIGINT";
} else {
if (length > 9) {
retval += "BIGINT";
} else {
if (length < 5) {
if (length < 3) {
retval += "TINYINT";
} else {
retval += "SMALLINT";
}
} else {
retval += "INTEGER";
}
}
retval += "DECIMAL(" + length + ")";
}

} else if (type == IValueMeta.TYPE_BIGNUMBER) {
// Fixed point value...
if (length
< 1) { // user configured no value for length. Use 16 digits, which is comparable to
// mantissa 2^53 of IEEE 754 binary64 "double".
length = 16;
}
if (precision
< 1) { // user configured no value for precision. Use 16 digits, which is comparable
// to IEEE 754 binary64 "double".
precision = 16;
}
retval += "DECIMAL(" + length + "," + precision + ")";
} else {
retval += "DOUBLE";
// Floating point value with double precision...
retval += "DOUBLE PRECISION";
}
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ public void testSqlStatements() {
nativeMeta.getAddColumnStatement("FOO", new ValueMetaBoolean("BAR"), "", false, "", false));

assertEquals(
"ALTER TABLE FOO ADD BAR BIGINT",
"ALTER TABLE FOO ADD BAR DOUBLE PRECISION",
nativeMeta.getAddColumnStatement(
"FOO", new ValueMetaNumber("BAR", 10, 0), "", false, "", false));

assertEquals(
"ALTER TABLE FOO ADD BAR BIGINT",
"ALTER TABLE FOO ADD BAR DECIMAL(10,16)",
nativeMeta.getAddColumnStatement(
"FOO", new ValueMetaBigNumber("BAR", 10, 0), "", false, "", false));

Expand All @@ -139,27 +139,27 @@ public void testSqlStatements() {
"FOO", new ValueMetaInteger("BAR", 10, 0), "", false, "", false));

assertEquals(
"ALTER TABLE FOO ADD BAR DOUBLE",
"ALTER TABLE FOO ADD BAR DOUBLE PRECISION",
nativeMeta.getAddColumnStatement(
"FOO", new ValueMetaNumber("BAR", 0, 0), "", false, "", false));

assertEquals(
"ALTER TABLE FOO ADD BAR INTEGER",
"ALTER TABLE FOO ADD BAR DOUBLE PRECISION",
nativeMeta.getAddColumnStatement(
"FOO", new ValueMetaNumber("BAR", 5, 0), "", false, "", false));

assertEquals(
"ALTER TABLE FOO ADD BAR DECIMAL(10, 3)",
"ALTER TABLE FOO ADD BAR DOUBLE PRECISION",
nativeMeta.getAddColumnStatement(
"FOO", new ValueMetaNumber("BAR", 10, 3), "", false, "", false));

assertEquals(
"ALTER TABLE FOO ADD BAR DECIMAL(10, 3)",
"ALTER TABLE FOO ADD BAR DECIMAL(10,3)",
nativeMeta.getAddColumnStatement(
"FOO", new ValueMetaBigNumber("BAR", 10, 3), "", false, "", false));

assertEquals(
"ALTER TABLE FOO ADD BAR DECIMAL(21, 4)",
"ALTER TABLE FOO ADD BAR DECIMAL(21,4)",
nativeMeta.getAddColumnStatement(
"FOO", new ValueMetaBigNumber("BAR", 21, 4), "", false, "", false));

Expand All @@ -179,25 +179,20 @@ public void testSqlStatements() {
"FOO", new ValueMetaString("BAR", 15, 0), "", false, "", false));

assertEquals(
"ALTER TABLE FOO ADD BAR BIGINT",
"ALTER TABLE FOO ADD BAR DOUBLE PRECISION",
nativeMeta.getAddColumnStatement(
"FOO",
new ValueMetaNumber("BAR", 10, -7),
"",
false,
"",
false)); // Bug here - invalid SQL
"FOO", new ValueMetaNumber("BAR", 10, -7), "", false, "", false));

assertEquals(
"ALTER TABLE FOO ADD BAR DECIMAL(22, 7)",
"ALTER TABLE FOO ADD BAR DECIMAL(22,7)",
nativeMeta.getAddColumnStatement(
"FOO", new ValueMetaBigNumber("BAR", 22, 7), "", false, "", false));
assertEquals(
"ALTER TABLE FOO ADD BAR DOUBLE",
"ALTER TABLE FOO ADD BAR DOUBLE PRECISION",
nativeMeta.getAddColumnStatement(
"FOO", new ValueMetaNumber("BAR", -10, 7), "", false, "", false));
assertEquals(
"ALTER TABLE FOO ADD BAR DECIMAL(5, 7)",
"ALTER TABLE FOO ADD BAR DOUBLE PRECISION",
nativeMeta.getAddColumnStatement(
"FOO", new ValueMetaNumber("BAR", 5, 7), "", false, "", false));
assertEquals(
Expand Down Expand Up @@ -252,12 +247,12 @@ public void testSqlStatements() {
"FOO", new ValueMetaInteger("BAR"), "BAR", false, "", false));

assertEquals(
"ALTER TABLE FOO ADD BAR BIGINT",
"ALTER TABLE FOO ADD BAR DECIMAL(10,16)",
nativeMeta.getAddColumnStatement(
"FOO", new ValueMetaBigNumber("BAR", 10, 0), "", false, "", false));

assertEquals(
"ALTER TABLE FOO ADD BAR DECIMAL(22, 0)",
"ALTER TABLE FOO ADD BAR DECIMAL(22,16)",
nativeMeta.getAddColumnStatement(
"FOO", new ValueMetaBigNumber("BAR", 22, 0), "", false, "", false));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,33 +296,35 @@ public String getFieldDefinition(
retval += "BIGINT NOT NULL PRIMARY KEY";
}
} else {
// Integer values...
if (precision == 0) {
if (length > 9) {
if (length < 19) {
// can hold signed values between -9223372036854775808 and 9223372036854775807
// 18 significant digits
retval += "BIGINT";
} else {
retval += "DECIMAL(" + length + ")";
}
} else {
if (type == IValueMeta.TYPE_INTEGER) {
// Integer values...
if (length < 3) {
retval += "TINYINT";
} else if (length < 5) {
retval += "SMALLINT";
} else if (length < 10) {
retval += "INT";
}
} else {
// Floating point values...
if (length > 15) {
retval += "DECIMAL(" + length;
if (precision > 0) {
retval += ", " + precision;
}
retval += ")";
} else if (length < 20) {
retval += "BIGINT";
} else {
// A double-precision floating-point number is accurate to approximately 15 decimal
// places.
// https://docs.cloudera.com/HDPDocuments/HDP2/HDP-2.0.0.2/ds_Hive/jdbc-hs2.html
retval += "DOUBLE";
retval += "DECIMAL(" + length + ")";
}
} else if (type == IValueMeta.TYPE_BIGNUMBER) {
// Fixed point value...
if (length
< 1) { // user configured no value for length. Use 16 digits, which is comparable to
// mantissa 2^53 of IEEE 754 binary64 "double".
length = 16;
}
if (precision
< 1) { // user configured no value for precision. Use 16 digits, which is comparable
// to IEEE 754 binary64 "double".
precision = 16;
}
retval += "DECIMAL(" + length + "," + precision + ")";
} else {
// Floating point value with double precision...
retval += "DOUBLE";
}
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,12 @@ public void testSqlStatements() {
nativeMeta.getAddColumnStatement("FOO", new ValueMetaBoolean("BAR"), "", false, "", false));

assertEquals(
"ALTER TABLE FOO ADD BAR BIGINT",
"ALTER TABLE FOO ADD BAR DOUBLE",
nativeMeta.getAddColumnStatement(
"FOO", new ValueMetaNumber("BAR", 10, 0), "", false, "", false));

assertEquals(
"ALTER TABLE FOO ADD BAR BIGINT",
"ALTER TABLE FOO ADD BAR DECIMAL(10,16)",
nativeMeta.getAddColumnStatement(
"FOO", new ValueMetaBigNumber("BAR", 10, 0), "", false, "", false));

Expand All @@ -280,12 +280,12 @@ public void testSqlStatements() {
"FOO", new ValueMetaInteger("BAR", 10, 0), "", false, "", false));

assertEquals(
"ALTER TABLE FOO ADD BAR INT",
"ALTER TABLE FOO ADD BAR DOUBLE",
nativeMeta.getAddColumnStatement(
"FOO", new ValueMetaNumber("BAR", 0, 0), "", false, "", false));

assertEquals(
"ALTER TABLE FOO ADD BAR INT",
"ALTER TABLE FOO ADD BAR DOUBLE",
nativeMeta.getAddColumnStatement(
"FOO", new ValueMetaNumber("BAR", 5, 0), "", false, "", false));

Expand All @@ -295,12 +295,12 @@ public void testSqlStatements() {
"FOO", new ValueMetaNumber("BAR", 10, 3), "", false, "", false));

assertEquals(
"ALTER TABLE FOO ADD BAR DOUBLE",
"ALTER TABLE FOO ADD BAR DECIMAL(10,3)",
nativeMeta.getAddColumnStatement(
"FOO", new ValueMetaBigNumber("BAR", 10, 3), "", false, "", false));

assertEquals(
"ALTER TABLE FOO ADD BAR DECIMAL(21, 4)",
"ALTER TABLE FOO ADD BAR DECIMAL(21,4)",
nativeMeta.getAddColumnStatement(
"FOO", new ValueMetaBigNumber("BAR", 21, 4), "", false, "", false));

Expand Down Expand Up @@ -330,7 +330,7 @@ public void testSqlStatements() {
false)); // Bug here - invalid SQL

assertEquals(
"ALTER TABLE FOO ADD BAR DECIMAL(22, 7)",
"ALTER TABLE FOO ADD BAR DECIMAL(22,7)",
nativeMeta.getAddColumnStatement(
"FOO", new ValueMetaBigNumber("BAR", 22, 7), "", false, "", false));
assertEquals(
Expand Down Expand Up @@ -373,7 +373,7 @@ public void testSqlStatements() {
"FOO", new ValueMetaString("BAR"), "", false, "", true));

assertEquals(
"ALTER TABLE FOO ADD BAR INT",
"ALTER TABLE FOO ADD BAR SMALLINT",
nativeMeta.getAddColumnStatement(
"FOO", new ValueMetaInteger("BAR", 4, 0), "", true, "", false));

Expand All @@ -383,12 +383,12 @@ public void testSqlStatements() {
"FOO", new ValueMetaInteger("BAR"), "BAR", false, "", false));

assertEquals(
"ALTER TABLE FOO ADD BAR BIGINT",
"ALTER TABLE FOO ADD BAR DECIMAL(10,16)",
nativeMeta.getAddColumnStatement(
"FOO", new ValueMetaBigNumber("BAR", 10, 0), "", false, "", false));

assertEquals(
"ALTER TABLE FOO ADD BAR DECIMAL(22)",
"ALTER TABLE FOO ADD BAR DECIMAL(22,16)",
nativeMeta.getAddColumnStatement(
"FOO", new ValueMetaBigNumber("BAR", 22, 0), "", false, "", false));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,22 +143,34 @@ public String getFieldDefinition(
retval.append(
"BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 0, INCREMENT BY 1) PRIMARY KEY");
} else {
if (length > 0) {
if (precision > 0 || length > 18) {
retval.append("NUMERIC(").append(length).append(", ").append(precision).append(')');
if (type == IValueMeta.TYPE_INTEGER) {
// Integer values...
if (length < 3) {
retval.append("TINYINT");
} else if (length < 5) {
retval.append("SMALLINT");
} else if (length < 10) {
retval.append("INT");
} else if (length < 20) {
retval.append("BIGINT");
} else {
if (length > 9) {
retval.append("BIGINT");
} else {
if (length < 5) {
retval.append("SMALLINT");
} else {
retval.append("INTEGER");
}
}
retval.append("DECIMAL(").append(length).append(")");
}

} else if (type == IValueMeta.TYPE_BIGNUMBER) {
// Fixed point value...
if (length
< 1) { // user configured no value for length. Use 16 digits, which is comparable to
// mantissa 2^53 of IEEE 754 binary64 "double".
length = 16;
}
if (precision
< 1) { // user configured no value for precision. Use 16 digits, which is comparable
// to IEEE 754 binary64 "double".
precision = 16;
}
retval.append("DECIMAL(").append(length).append(",").append(precision).append(")");
} else {
// Floating point value with double precision...
retval.append("DOUBLE PRECISION");
}
}
Expand Down Expand Up @@ -190,7 +202,7 @@ public String getFieldDefinition(

@Override
public String getExtraOptionsHelpText() {
return "http://hsqldb.sourceforge.net/doc/guide/ch04.html#N109DA";
return "https://hsqldb.org/doc/2.0/guide/dbproperties-chapt.html";
}

@Override
Expand Down
Loading
Loading