Skip to content

Commit

Permalink
TEIIDDES-2018 added post-processing of each column to fine-tune the d…
Browse files Browse the repository at this point in the history
…atatype properties

 * Utilized logic similar to the JDBC import RelationalModelProcessorImpl
 * Mapping/using native type in some instances to match JDBC import mapping
  • Loading branch information
blafond committed Jan 31, 2014
1 parent 8364545 commit 41c47a3
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.teiid.designer.core.ModelerCore;
import org.teiid.designer.ddl.importer.DdlImporterI18n;
import org.teiid.designer.ddl.importer.TeiidDDLConstants;
import org.teiid.designer.relational.RelationalConstants;
import org.teiid.designer.relational.model.RelationalAccessPattern;
import org.teiid.designer.relational.model.RelationalColumn;
import org.teiid.designer.relational.model.RelationalForeignKey;
Expand Down Expand Up @@ -58,6 +59,46 @@ public class TeiidDdlImporter extends StandardImporter {
private static final String NS_DESIGNER_SALESFORCE = "salesforce"; //$NON-NLS-1$
private static final String NS_DESIGNER_RELATIONAL = "relational"; //$NON-NLS-1$

interface TYPES_UPPER {
String ARRAY = "ARRAY"; //$NON-NLS-1$
String BIGDECIMAL = "BIGDECIMAL"; //$NON-NLS-1$
String BINARY = "BINARY"; //$NON-NLS-1$
String BIT = "BIT"; //$NON-NLS-1$
String BLOB = "BLOB"; //$NON-NLS-1$
String BYTE = "BYTE"; //$NON-NLS-1$
String CHAR = "CHAR"; //$NON-NLS-1$
String CLOB = "CLOB"; //$NON-NLS-1$
String DATE = "DATE"; //$NON-NLS-1$
String DATETIME = "DATETIME"; //$NON-NLS-1$
String DECIMAL = "DECIMAL"; //$NON-NLS-1$
String DOUBLE = "DOUBLE"; //$NON-NLS-1$
String FLOAT = "FLOAT"; //$NON-NLS-1$
String INT = "INT"; //$NON-NLS-1$
String INTEGER = "INTEGER"; //$NON-NLS-1$
String LONGVARBINARY = "LONGVARBINARY"; //$NON-NLS-1$
String LONGVARCHAR = "LONGVARCHAR"; //$NON-NLS-1$
String NCHAR = "NCHAR"; //$NON-NLS-1$
String NUMERIC = "NUMERIC"; //$NON-NLS-1$
String OBJECT = "OBJECT"; //$NON-NLS-1$
String REAL = "REAL"; //$NON-NLS-1$
String REF = "REF"; //$NON-NLS-1$
String SHORT = "SHORT"; //$NON-NLS-1$
String STRING = "STRING"; //$NON-NLS-1$
String SMALLINT = "SMALLINT"; //$NON-NLS-1$
String TIMES = "TIME"; //$NON-NLS-1$
String TIMESTAMP = "TIMESTAMP"; //$NON-NLS-1$
String TINYINT = "TINYINT"; //$NON-NLS-1$
String VARBINARY = "VARBINARY"; //$NON-NLS-1$
String VARCHAR = "VARCHAR"; //$NON-NLS-1$
}

static int DEFAULT_NULL_VALUE_COUNT = -1;

/*
* return !(type == Types.LONGVARBINARY || type == Types.LONGVARCHAR || type == Types.VARBINARY || type == Types.VARCHAR
|| type == Types.ARRAY || type == Types.BLOB || type == Types.CLOB);
*/

private class TeiidInfo extends Info {

/**
Expand Down Expand Up @@ -616,6 +657,13 @@ private void processTeiidProcedureOptions(List<AstNode> optionNodes, RelationalP
* @param column
*/
private void processTeiidColumnOptions(List<AstNode> optionNodes, RelationalColumn column) {
// Need to pre-process a couple things

// if( column.getNullValueCount() == 0 ) {
// // DDL Parser uses a default value of 0 so we need to check and convert to Teiid's expected null value of -1
// column.setNullValueCount(DEFAULT_NULL_VALUE_COUNT);
// }

Iterator<AstNode> nodeIter = optionNodes.iterator();
while(nodeIter.hasNext()) {
AstNode optionNode = nodeIter.next();
Expand Down Expand Up @@ -654,6 +702,7 @@ private void processTeiidColumnOptions(List<AstNode> optionNodes, RelationalColu
} else if(optionName.equalsIgnoreCase(TeiidDDLConstants.NATIVE_TYPE)) {
column.setNativeType(optionValueStr);
nodeIter.remove();
resolveColumnDatatype(column, optionValueStr);
} else if(optionName.equalsIgnoreCase(TeiidDDLConstants.NULL_VALUE_COUNT)) {
column.setNullValueCount(Integer.parseInt(optionValueStr));
nodeIter.remove();
Expand All @@ -668,6 +717,60 @@ private void processTeiidColumnOptions(List<AstNode> optionNodes, RelationalColu
}
}
}

private void resolveColumnDatatype(RelationalColumn column, String nativeType) {
if( column.getDatatype().equalsIgnoreCase(TYPES_UPPER.INTEGER) && nativeType.equalsIgnoreCase(TYPES_UPPER.INT) ) {
column.setDatatype(nativeType);
} else if( column.getDatatype().equalsIgnoreCase(TYPES_UPPER.STRING) && nativeType.equalsIgnoreCase(TYPES_UPPER.CHAR ) ) {
column.setDatatype(nativeType);
} else if( column.getDatatype().equalsIgnoreCase(TYPES_UPPER.VARBINARY) && nativeType.equalsIgnoreCase(TYPES_UPPER.BINARY ) ) {
column.setDatatype(TYPES_UPPER.OBJECT.toLowerCase());
} else if( column.getDatatype().equalsIgnoreCase(TYPES_UPPER.TIMESTAMP) && nativeType.equalsIgnoreCase(TYPES_UPPER.DATETIME ) ) {
} else if( column.getDatatype().equalsIgnoreCase(TYPES_UPPER.DOUBLE) && nativeType.equalsIgnoreCase(TYPES_UPPER.FLOAT ) ) {
column.setDatatype(nativeType);
if( column.getPrecision() == 0 ) {
column.setPrecision(53);
}
} else if( column.getDatatype().equalsIgnoreCase(TYPES_UPPER.BIGDECIMAL) && nativeType.equalsIgnoreCase(TYPES_UPPER.DECIMAL ) ) {
column.setDatatype(nativeType);
} else if( column.getDatatype().equalsIgnoreCase(TYPES_UPPER.SHORT) && nativeType.equalsIgnoreCase(TYPES_UPPER.TINYINT ) ) {
column.setDatatype(TYPES_UPPER.BYTE.toLowerCase());
} else if( column.getDatatype().equalsIgnoreCase(TYPES_UPPER.FLOAT) && nativeType.equalsIgnoreCase(TYPES_UPPER.REAL ) ) {
if( column.getPrecision() == 0 ) {
column.setPrecision(24);
}
}


// Not enough info in DDL to determine if fixed length data type so calling it here
column.setLengthFixed(isFixedLength(column.getDatatype()));

// From RelationalModelProcessor....
if (column.getSearchability().equalsIgnoreCase(RelationalConstants.SEARCHABILITY.ALL_EXCEPT_LIKE) ) {
column.setCaseSensitive(false);
} else if (column.getSearchability().equalsIgnoreCase(RelationalConstants.SEARCHABILITY.SEARCHABLE) ) {
column.setCaseSensitive(true);
} else {
column.setCaseSensitive(false);
}
}

/**
* Method that can identify if a data type is fixed length or not
* (See <code>org.teiid.designer.jdbc.relational.impl.RelationalModelProcessorImpl</code> used for JDBC import)
* @param typeName
* @return True if the specified type should be considered fixed-length.
* @since 4.2
*/
protected boolean isFixedLength( final String typeName ) {
return !(TYPES_UPPER.LONGVARBINARY.equalsIgnoreCase(typeName) ||
TYPES_UPPER.LONGVARCHAR.equalsIgnoreCase(typeName) ||
TYPES_UPPER.VARBINARY.equalsIgnoreCase(typeName) ||
TYPES_UPPER.VARCHAR.equalsIgnoreCase(typeName) ||
TYPES_UPPER.ARRAY.equalsIgnoreCase(typeName) ||
TYPES_UPPER.BLOB.equalsIgnoreCase(typeName) ||
TYPES_UPPER.CLOB.equalsIgnoreCase(typeName));
}

/**
* Get the deterministic boolean from the DETERMINISM option string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class RelationalColumn extends RelationalReference {
public static final String DEFAULT_MAXIMUM_VALUE = null;
public static final String DEFAULT_MINIMUM_VALUE = null;
public static final int DEFAULT_PRECISION = 0;
public static final int DEFAULT_NUMERIC_PRECISION = 1;
public static final int DEFAULT_RADIX = 0;
public static final int DEFAULT_SCALE = 0;
public static final boolean DEFAULT_SIGNED = true;
Expand All @@ -73,13 +74,13 @@ public class RelationalColumn extends RelationalReference {

public static final int DEFAULT_STRING_LENGTH = 4000;

private int distinctValueCount;
private int nullValueCount;
private int distinctValueCount = DEFAULT_DISTINCT_VALUE_COUNT;
private int nullValueCount = DEFAULT_NULL_VALUE_COUNT;
private String datatype;
private String nativeType;
private String nullable;
private String nullable = DEFAULT_NULLABLE;
private boolean autoIncremented;
private boolean caseSensitive;
private boolean caseSensitive = DEFAULT_CASE_SENSITIVE;
private String characterSetName;
private String collationName;
private boolean currency;
Expand All @@ -93,7 +94,7 @@ public class RelationalColumn extends RelationalReference {
private int scale;
private int radix;
private int characterOctetLength;
private boolean signed;
private boolean signed = DEFAULT_SIGNED;
private String searchability = DEFAULT_SEARCHABILITY;
private boolean selectable = DEFAULT_SELECTABLE;
private boolean updateable = DEFAULT_UPDATEABLE;
Expand Down Expand Up @@ -152,6 +153,15 @@ public String getDatatype() {
*/
public void setDatatype( String datatype ) {
this.datatype = datatype;
if( this.precision == DEFAULT_PRECISION &&
(this.datatype.equalsIgnoreCase("INTEGER") || //$NON-NLS-1$
this.datatype.equalsIgnoreCase("DECIMAL") || //$NON-NLS-1$
this.datatype.equalsIgnoreCase("LONG") || //$NON-NLS-1$
this.datatype.equalsIgnoreCase("SHORT") || //$NON-NLS-1$
this.datatype.equalsIgnoreCase("BIGDECIMAL") || //$NON-NLS-1$
this.datatype.equalsIgnoreCase("BIGINTEGER")) ) { //$NON-NLS-1$
setPrecision(DEFAULT_NUMERIC_PRECISION);
}
}
/**
* @return nativeType
Expand Down

0 comments on commit 41c47a3

Please sign in to comment.