@Test( expected = KettleException.class ) public void testGetMapping_UndefinedColumns() throws Exception { HBaseService hBaseService = mock( HBaseService.class ); MappingDefinition mappingDefinition = buildMappingDefinitionForGetMapping(); mappingDefinition.setMappingColumns( Collections.<MappingColumn>emptyList() ); MappingUtils.getMapping( mappingDefinition, hBaseService ); }
public static Mapping getMapping( MappingDefinition mappingDefinition, HBaseService hBaseService ) throws KettleException { final String tableName = mappingDefinition.getTableName(); if ( Const.isEmpty( tableName ) || Const.isEmpty( mappingDefinition.getMappingName() ) ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.MissingTableMappingName" ) ); } if ( mappingDefinition.getMappingColumns() == null || mappingDefinition.getMappingColumns().isEmpty() ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.NoFieldsDefined" ) ); } Mapping theMapping = hBaseService.getMappingFactory().createMapping( tableName, mappingDefinition.getMappingName() ); final boolean isTupleMapping = isTupleMapping( mappingDefinition ); if ( isTupleMapping ) { theMapping.setTupleMapping( true ); } List<MappingColumn> mappingColumns = mappingDefinition.getMappingColumns(); int columnNumber = 0; boolean keyDefined = false; for ( MappingColumn column : mappingColumns ) { columnNumber++; final String alias = column.getAlias(); final boolean isKey = column.isKey(); if ( isKey ) { if ( keyDefined ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.MoreThanOneKey" ) ); } keyDefined = true; } String family = null; if ( !Const.isEmpty( column.getColumnFamily() ) ) { family = column.getColumnFamily(); } else if ( !isKey && !isTupleMapping ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.FamilyIssue" ) + ": " + columnNumber ); } String colName = null; if ( !Const.isEmpty( column.getColumnName() ) ) { colName = column.getColumnName(); } else if ( !isKey && !isTupleMapping ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.ColumnIssue" ) + ": " + columnNumber ); } String type = null; if ( !Const.isEmpty( column.getType() ) ) { type = column.getType(); } else { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.TypeIssue" ) + ": " + columnNumber ); } HBaseValueMetaInterfaceFactory valueMetaInterfaceFactory = hBaseService.getHBaseValueMetaInterfaceFactory(); if ( isKey ) { if ( Const.isEmpty( alias ) ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.NoAliasForKey" ) ); } if ( isTupleMapping ) { theMapping.setKeyName( alias ); theMapping.setTupleFamilies( family ); } else { theMapping.setKeyName( alias ); } HBaseValueMetaInterface valueMeta = valueMetaInterfaceFactory.createHBaseValueMetaInterface( null, null, alias, 0, UNDEFINED_VALUE, UNDEFINED_VALUE ); valueMeta.setKey( true ); try { theMapping.setKeyTypeAsString( type ); valueMeta.setType( HBaseInput.getKettleTypeByKeyType( theMapping.getKeyType() ) ); } catch ( Exception ex ) { } } else { try { HBaseValueMetaInterface valueMeta = buildNonKeyValueMeta( alias, family, colName, type, column.getIndexedValues(), hBaseService ); theMapping.addMappedColumn( valueMeta, isTupleMapping ); } catch ( Exception ex ) { String message = Messages.getString( "MappingDialog.Error.Message1.DuplicateColumn" ) + family + "," + colName + Messages .getString( "MappingDialog.Error.Message2.DuplicateColumn" ); throw new KettleException( message ); } } } if ( !keyDefined ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.NoKeyDefined" ) ); } return theMapping; }
MappingUtils { public static Mapping getMapping( MappingDefinition mappingDefinition, HBaseService hBaseService ) throws KettleException { final String tableName = mappingDefinition.getTableName(); if ( Const.isEmpty( tableName ) || Const.isEmpty( mappingDefinition.getMappingName() ) ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.MissingTableMappingName" ) ); } if ( mappingDefinition.getMappingColumns() == null || mappingDefinition.getMappingColumns().isEmpty() ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.NoFieldsDefined" ) ); } Mapping theMapping = hBaseService.getMappingFactory().createMapping( tableName, mappingDefinition.getMappingName() ); final boolean isTupleMapping = isTupleMapping( mappingDefinition ); if ( isTupleMapping ) { theMapping.setTupleMapping( true ); } List<MappingColumn> mappingColumns = mappingDefinition.getMappingColumns(); int columnNumber = 0; boolean keyDefined = false; for ( MappingColumn column : mappingColumns ) { columnNumber++; final String alias = column.getAlias(); final boolean isKey = column.isKey(); if ( isKey ) { if ( keyDefined ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.MoreThanOneKey" ) ); } keyDefined = true; } String family = null; if ( !Const.isEmpty( column.getColumnFamily() ) ) { family = column.getColumnFamily(); } else if ( !isKey && !isTupleMapping ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.FamilyIssue" ) + ": " + columnNumber ); } String colName = null; if ( !Const.isEmpty( column.getColumnName() ) ) { colName = column.getColumnName(); } else if ( !isKey && !isTupleMapping ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.ColumnIssue" ) + ": " + columnNumber ); } String type = null; if ( !Const.isEmpty( column.getType() ) ) { type = column.getType(); } else { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.TypeIssue" ) + ": " + columnNumber ); } HBaseValueMetaInterfaceFactory valueMetaInterfaceFactory = hBaseService.getHBaseValueMetaInterfaceFactory(); if ( isKey ) { if ( Const.isEmpty( alias ) ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.NoAliasForKey" ) ); } if ( isTupleMapping ) { theMapping.setKeyName( alias ); theMapping.setTupleFamilies( family ); } else { theMapping.setKeyName( alias ); } HBaseValueMetaInterface valueMeta = valueMetaInterfaceFactory.createHBaseValueMetaInterface( null, null, alias, 0, UNDEFINED_VALUE, UNDEFINED_VALUE ); valueMeta.setKey( true ); try { theMapping.setKeyTypeAsString( type ); valueMeta.setType( HBaseInput.getKettleTypeByKeyType( theMapping.getKeyType() ) ); } catch ( Exception ex ) { } } else { try { HBaseValueMetaInterface valueMeta = buildNonKeyValueMeta( alias, family, colName, type, column.getIndexedValues(), hBaseService ); theMapping.addMappedColumn( valueMeta, isTupleMapping ); } catch ( Exception ex ) { String message = Messages.getString( "MappingDialog.Error.Message1.DuplicateColumn" ) + family + "," + colName + Messages .getString( "MappingDialog.Error.Message2.DuplicateColumn" ); throw new KettleException( message ); } } } if ( !keyDefined ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.NoKeyDefined" ) ); } return theMapping; } }
MappingUtils { public static Mapping getMapping( MappingDefinition mappingDefinition, HBaseService hBaseService ) throws KettleException { final String tableName = mappingDefinition.getTableName(); if ( Const.isEmpty( tableName ) || Const.isEmpty( mappingDefinition.getMappingName() ) ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.MissingTableMappingName" ) ); } if ( mappingDefinition.getMappingColumns() == null || mappingDefinition.getMappingColumns().isEmpty() ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.NoFieldsDefined" ) ); } Mapping theMapping = hBaseService.getMappingFactory().createMapping( tableName, mappingDefinition.getMappingName() ); final boolean isTupleMapping = isTupleMapping( mappingDefinition ); if ( isTupleMapping ) { theMapping.setTupleMapping( true ); } List<MappingColumn> mappingColumns = mappingDefinition.getMappingColumns(); int columnNumber = 0; boolean keyDefined = false; for ( MappingColumn column : mappingColumns ) { columnNumber++; final String alias = column.getAlias(); final boolean isKey = column.isKey(); if ( isKey ) { if ( keyDefined ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.MoreThanOneKey" ) ); } keyDefined = true; } String family = null; if ( !Const.isEmpty( column.getColumnFamily() ) ) { family = column.getColumnFamily(); } else if ( !isKey && !isTupleMapping ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.FamilyIssue" ) + ": " + columnNumber ); } String colName = null; if ( !Const.isEmpty( column.getColumnName() ) ) { colName = column.getColumnName(); } else if ( !isKey && !isTupleMapping ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.ColumnIssue" ) + ": " + columnNumber ); } String type = null; if ( !Const.isEmpty( column.getType() ) ) { type = column.getType(); } else { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.TypeIssue" ) + ": " + columnNumber ); } HBaseValueMetaInterfaceFactory valueMetaInterfaceFactory = hBaseService.getHBaseValueMetaInterfaceFactory(); if ( isKey ) { if ( Const.isEmpty( alias ) ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.NoAliasForKey" ) ); } if ( isTupleMapping ) { theMapping.setKeyName( alias ); theMapping.setTupleFamilies( family ); } else { theMapping.setKeyName( alias ); } HBaseValueMetaInterface valueMeta = valueMetaInterfaceFactory.createHBaseValueMetaInterface( null, null, alias, 0, UNDEFINED_VALUE, UNDEFINED_VALUE ); valueMeta.setKey( true ); try { theMapping.setKeyTypeAsString( type ); valueMeta.setType( HBaseInput.getKettleTypeByKeyType( theMapping.getKeyType() ) ); } catch ( Exception ex ) { } } else { try { HBaseValueMetaInterface valueMeta = buildNonKeyValueMeta( alias, family, colName, type, column.getIndexedValues(), hBaseService ); theMapping.addMappedColumn( valueMeta, isTupleMapping ); } catch ( Exception ex ) { String message = Messages.getString( "MappingDialog.Error.Message1.DuplicateColumn" ) + family + "," + colName + Messages .getString( "MappingDialog.Error.Message2.DuplicateColumn" ); throw new KettleException( message ); } } } if ( !keyDefined ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.NoKeyDefined" ) ); } return theMapping; }  }
MappingUtils { public static Mapping getMapping( MappingDefinition mappingDefinition, HBaseService hBaseService ) throws KettleException { final String tableName = mappingDefinition.getTableName(); if ( Const.isEmpty( tableName ) || Const.isEmpty( mappingDefinition.getMappingName() ) ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.MissingTableMappingName" ) ); } if ( mappingDefinition.getMappingColumns() == null || mappingDefinition.getMappingColumns().isEmpty() ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.NoFieldsDefined" ) ); } Mapping theMapping = hBaseService.getMappingFactory().createMapping( tableName, mappingDefinition.getMappingName() ); final boolean isTupleMapping = isTupleMapping( mappingDefinition ); if ( isTupleMapping ) { theMapping.setTupleMapping( true ); } List<MappingColumn> mappingColumns = mappingDefinition.getMappingColumns(); int columnNumber = 0; boolean keyDefined = false; for ( MappingColumn column : mappingColumns ) { columnNumber++; final String alias = column.getAlias(); final boolean isKey = column.isKey(); if ( isKey ) { if ( keyDefined ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.MoreThanOneKey" ) ); } keyDefined = true; } String family = null; if ( !Const.isEmpty( column.getColumnFamily() ) ) { family = column.getColumnFamily(); } else if ( !isKey && !isTupleMapping ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.FamilyIssue" ) + ": " + columnNumber ); } String colName = null; if ( !Const.isEmpty( column.getColumnName() ) ) { colName = column.getColumnName(); } else if ( !isKey && !isTupleMapping ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.ColumnIssue" ) + ": " + columnNumber ); } String type = null; if ( !Const.isEmpty( column.getType() ) ) { type = column.getType(); } else { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.TypeIssue" ) + ": " + columnNumber ); } HBaseValueMetaInterfaceFactory valueMetaInterfaceFactory = hBaseService.getHBaseValueMetaInterfaceFactory(); if ( isKey ) { if ( Const.isEmpty( alias ) ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.NoAliasForKey" ) ); } if ( isTupleMapping ) { theMapping.setKeyName( alias ); theMapping.setTupleFamilies( family ); } else { theMapping.setKeyName( alias ); } HBaseValueMetaInterface valueMeta = valueMetaInterfaceFactory.createHBaseValueMetaInterface( null, null, alias, 0, UNDEFINED_VALUE, UNDEFINED_VALUE ); valueMeta.setKey( true ); try { theMapping.setKeyTypeAsString( type ); valueMeta.setType( HBaseInput.getKettleTypeByKeyType( theMapping.getKeyType() ) ); } catch ( Exception ex ) { } } else { try { HBaseValueMetaInterface valueMeta = buildNonKeyValueMeta( alias, family, colName, type, column.getIndexedValues(), hBaseService ); theMapping.addMappedColumn( valueMeta, isTupleMapping ); } catch ( Exception ex ) { String message = Messages.getString( "MappingDialog.Error.Message1.DuplicateColumn" ) + family + "," + colName + Messages .getString( "MappingDialog.Error.Message2.DuplicateColumn" ); throw new KettleException( message ); } } } if ( !keyDefined ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.NoKeyDefined" ) ); } return theMapping; }  static MappingAdmin getMappingAdmin( ConfigurationProducer cProducer ); static MappingAdmin getMappingAdmin( HBaseService hBaseService, VariableSpace variableSpace, String siteConfig,
      String defaultConfig ); static Mapping getMapping( MappingDefinition mappingDefinition, HBaseService hBaseService ); static HBaseValueMetaInterface buildNonKeyValueMeta( String alias, String family, String columnName,
      String type, String indexedVals, HBaseService hBaseService ); static boolean isTupleMapping( MappingDefinition mappingDefinition ); static boolean isTupleMappingColumn( String columnName ); }
MappingUtils { public static Mapping getMapping( MappingDefinition mappingDefinition, HBaseService hBaseService ) throws KettleException { final String tableName = mappingDefinition.getTableName(); if ( Const.isEmpty( tableName ) || Const.isEmpty( mappingDefinition.getMappingName() ) ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.MissingTableMappingName" ) ); } if ( mappingDefinition.getMappingColumns() == null || mappingDefinition.getMappingColumns().isEmpty() ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.NoFieldsDefined" ) ); } Mapping theMapping = hBaseService.getMappingFactory().createMapping( tableName, mappingDefinition.getMappingName() ); final boolean isTupleMapping = isTupleMapping( mappingDefinition ); if ( isTupleMapping ) { theMapping.setTupleMapping( true ); } List<MappingColumn> mappingColumns = mappingDefinition.getMappingColumns(); int columnNumber = 0; boolean keyDefined = false; for ( MappingColumn column : mappingColumns ) { columnNumber++; final String alias = column.getAlias(); final boolean isKey = column.isKey(); if ( isKey ) { if ( keyDefined ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.MoreThanOneKey" ) ); } keyDefined = true; } String family = null; if ( !Const.isEmpty( column.getColumnFamily() ) ) { family = column.getColumnFamily(); } else if ( !isKey && !isTupleMapping ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.FamilyIssue" ) + ": " + columnNumber ); } String colName = null; if ( !Const.isEmpty( column.getColumnName() ) ) { colName = column.getColumnName(); } else if ( !isKey && !isTupleMapping ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.ColumnIssue" ) + ": " + columnNumber ); } String type = null; if ( !Const.isEmpty( column.getType() ) ) { type = column.getType(); } else { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.TypeIssue" ) + ": " + columnNumber ); } HBaseValueMetaInterfaceFactory valueMetaInterfaceFactory = hBaseService.getHBaseValueMetaInterfaceFactory(); if ( isKey ) { if ( Const.isEmpty( alias ) ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.NoAliasForKey" ) ); } if ( isTupleMapping ) { theMapping.setKeyName( alias ); theMapping.setTupleFamilies( family ); } else { theMapping.setKeyName( alias ); } HBaseValueMetaInterface valueMeta = valueMetaInterfaceFactory.createHBaseValueMetaInterface( null, null, alias, 0, UNDEFINED_VALUE, UNDEFINED_VALUE ); valueMeta.setKey( true ); try { theMapping.setKeyTypeAsString( type ); valueMeta.setType( HBaseInput.getKettleTypeByKeyType( theMapping.getKeyType() ) ); } catch ( Exception ex ) { } } else { try { HBaseValueMetaInterface valueMeta = buildNonKeyValueMeta( alias, family, colName, type, column.getIndexedValues(), hBaseService ); theMapping.addMappedColumn( valueMeta, isTupleMapping ); } catch ( Exception ex ) { String message = Messages.getString( "MappingDialog.Error.Message1.DuplicateColumn" ) + family + "," + colName + Messages .getString( "MappingDialog.Error.Message2.DuplicateColumn" ); throw new KettleException( message ); } } } if ( !keyDefined ) { throw new KettleException( Messages.getString( "MappingDialog.Error.Message.NoKeyDefined" ) ); } return theMapping; }  static MappingAdmin getMappingAdmin( ConfigurationProducer cProducer ); static MappingAdmin getMappingAdmin( HBaseService hBaseService, VariableSpace variableSpace, String siteConfig,
      String defaultConfig ); static Mapping getMapping( MappingDefinition mappingDefinition, HBaseService hBaseService ); static HBaseValueMetaInterface buildNonKeyValueMeta( String alias, String family, String columnName,
      String type, String indexedVals, HBaseService hBaseService ); static boolean isTupleMapping( MappingDefinition mappingDefinition ); static boolean isTupleMappingColumn( String columnName ); static final int TUPLE_COLUMNS_COUNT; static final int UNDEFINED_VALUE; static final String TUPLE_MAPPING_VISIBILITY; }