@Override
  public String getFieldDefinition( ValueMetaInterface v, String tk, String pk, boolean useAutoinc,
                                    boolean addFieldName, boolean addCr ) {
    StringBuilder retval = new StringBuilder( 128 );

    String fieldname = v.getName();
    int length = v.getLength();
    int precision = v.getPrecision();

    if ( addFieldName ) {
      retval.append( fieldname ).append( ' ' );
    }

    int type = v.getType();
    switch ( type ) {
      case ValueMetaInterface.TYPE_TIMESTAMP:
      case ValueMetaInterface.TYPE_DATE:
        retval.append( "TIMESTAMP" );
        break;
      case ValueMetaInterface.TYPE_BOOLEAN:
        if ( supportsBooleanDataType() ) {
          retval.append( "BOOLEAN" );
        } else {
          retval.append( "CHAR(1)" );
        }
        break;
      case ValueMetaInterface.TYPE_NUMBER:
      case ValueMetaInterface.TYPE_INTEGER:
      case ValueMetaInterface.TYPE_BIGNUMBER:
        if ( fieldname.equalsIgnoreCase( tk ) || // Technical key
            fieldname.equalsIgnoreCase( pk ) // Primary key
        ) {
          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( ')' );
            } else {
              if ( length > 9 ) {
                retval.append( "BIGINT" );
              } else {
                if ( length < 5 ) {
                  retval.append( "SMALLINT" );
                } else {
                  retval.append( "INTEGER" );
                }
              }
            }

          } else {
            retval.append( "DOUBLE PRECISION" );
          }
        }
        break;
      case ValueMetaInterface.TYPE_STRING:
        if ( length >= DatabaseMeta.CLOB_LENGTH ) {
          retval.append( "LONGVARCHAR" );
        } else {
          retval.append( "VARCHAR" );
          if ( length > 0 ) {
            retval.append( '(' ).append( length );
          } else {
            retval.append( '(' ); // Maybe use some default DB String length?
          }
          retval.append( ')' );
        }
        break;
      default:
        retval.append( " UNKNOWN" );
        break;
    }

    if ( addCr ) {
      retval.append( Const.CR );
    }

    return retval.toString();
  }
@Test
  public void testGetFieldDefinition() throws Exception {
    ValueMetaInterface vm = new ValueMetaString();
    String sql = hypersonicDatabaseMeta.getFieldDefinition( vm, null, null, false, false, false );
    String expectedSql = "VARCHAR()";
    assertEquals( "Check PDI-11461 without length", expectedSql, sql );
    vm.setLength( DatabaseMeta.CLOB_LENGTH - 1 );
    sql = hypersonicDatabaseMeta.getFieldDefinition( vm, null, null, false, false, false );
    expectedSql = "VARCHAR(" + ( DatabaseMeta.CLOB_LENGTH - 1 ) + ")";
    assertEquals( "Check PDI-11461 with length", expectedSql, sql );
    vm.setLength( DatabaseMeta.CLOB_LENGTH );
    sql = hypersonicDatabaseMeta.getFieldDefinition( vm, null, null, false, false, false );
    expectedSql = "LONGVARCHAR";
    assertEquals( "Check PDI-11461 with clob/text length", expectedSql, sql );
  }