Skip to content

Commit

Permalink
Merge pull request #3534 from zypjava/master
Browse files Browse the repository at this point in the history
Set Database Fields comment  and Doris dataTypes mapping
  • Loading branch information
usbrandon committed Jan 27, 2024
2 parents 55a63f0 + fb61d9a commit 56009f9
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2143,6 +2143,7 @@ private IRowMeta getQueryFieldsFromDatabaseMetaData(String sql) throws Exception
while (columns.next()) {
IValueMeta valueMeta = null;
String name = columns.getString("COLUMN_NAME");
String comments = columns.getString("REMARKS");
String type = columns.getString("SOURCE_DATA_TYPE");
int size = columns.getInt("COLUMN_SIZE");
if (type.equals("Integer") || type.equals("Long")) {
Expand All @@ -2166,7 +2167,7 @@ private IRowMeta getQueryFieldsFromDatabaseMetaData(String sql) throws Exception
}
if (valueMeta != null) {
valueMeta.setName(name);
valueMeta.setComments(name);
valueMeta.setComments(comments);
valueMeta.setLength(size);
valueMeta.setOriginalColumnTypeName(type);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,115 @@
*/
package org.apache.hop.databases.doris;

import org.apache.hop.core.Const;
import org.apache.hop.core.database.DatabaseMeta;
import org.apache.hop.core.database.DatabaseMetaPlugin;
import org.apache.hop.core.gui.plugin.GuiPlugin;
import org.apache.hop.core.row.IValueMeta;
import org.apache.hop.databases.mysql.MySqlDatabaseMeta;

@DatabaseMetaPlugin(type = "DORIS", typeDescription = "Apache Doris", documentationUrl = "/database/databases/doris.html")
@GuiPlugin(id = "GUI-DorisDatabaseMeta")
public class DorisDatabaseMeta extends MySqlDatabaseMeta {}
public class DorisDatabaseMeta extends MySqlDatabaseMeta {

@Override
public String getFieldDefinition(
IValueMeta v, String tk, String pk, boolean useAutoinc, boolean addFieldName, boolean addCR) {
String retval = "";

String fieldname = v.getName();
if (v.getLength() == DatabaseMeta.CLOB_LENGTH) {
v.setLength(getMaxTextFieldLength());
}
int length = v.getLength();
int precision = v.getPrecision();

if (addFieldName) {
retval += fieldname + " ";
}

int type = v.getType();
switch (type) {
case IValueMeta.TYPE_TIMESTAMP:
case IValueMeta.TYPE_DATE:
retval += "DATETIME";
break;
case IValueMeta.TYPE_BOOLEAN:
if (isSupportsBooleanDataType()) {
retval += "BOOLEAN";
} else {
retval += "CHAR(1)";
}
break;

case IValueMeta.TYPE_NUMBER:
case IValueMeta.TYPE_INTEGER:
case IValueMeta.TYPE_BIGNUMBER:
if (fieldname.equalsIgnoreCase(tk)
|| // Technical key
fieldname.equalsIgnoreCase(pk) // Primary key
) {
if (useAutoinc) {
retval += "BIGINT AUTO_INCREMENT NOT NULL PRIMARY KEY";
} else {
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 {
retval += "INT";
}
} else {
// Floating point values...
if (length > 15) {
retval += "DECIMAL(" + length;
if (precision > 0) {
retval += ", " + precision;
}
retval += ")";
} else {
// A double-precision floating-point number is accurate to approximately 15 decimal
// places.
// http://mysql.mirrors-r-us.net/doc/refman/5.1/en/numeric-type-overview.html
retval += "DOUBLE";
}
}
}
break;
case IValueMeta.TYPE_STRING:
if (length > 0) {
if (length == 1) {
retval += "CHAR(1)";
} else if (length < 65533) {
retval += "VARCHAR(" + length + ")";
} else {
retval += "STRING";
}
} else {
retval += "STRING";
}
break;
case IValueMeta.TYPE_BINARY:
retval += "BITMAP";
break;
default:
retval += " UNKNOWN";
break;
}

if (addCR) {
retval += Const.CR;
}

return retval;
}
}

0 comments on commit 56009f9

Please sign in to comment.