Search in sources :

Example 61 with CharacterCodingException

use of java.nio.charset.CharacterCodingException in project hive by apache.

the class LazyHiveChar method init.

@Override
public void init(ByteArrayRef bytes, int start, int length) {
    if (oi.isEscaped()) {
        Text textData = data.getTextValue();
        // This is doing a lot of copying here, this could be improved by enforcing length
        // at the same time as escaping rather than as separate steps.
        LazyUtils.copyAndEscapeStringDataToText(bytes.getData(), start, length, oi.getEscapeChar(), textData);
        data.set(textData.toString(), maxLength);
        isNull = false;
    } else {
        String byteData = null;
        try {
            byteData = Text.decode(bytes.getData(), start, length);
            data.set(byteData, maxLength);
            isNull = false;
        } catch (CharacterCodingException e) {
            isNull = true;
            LOG.debug("Data not in the HiveChar data type range so converted to null.", e);
        }
    }
}
Also used : Text(org.apache.hadoop.io.Text) CharacterCodingException(java.nio.charset.CharacterCodingException)

Example 62 with CharacterCodingException

use of java.nio.charset.CharacterCodingException in project robovm by robovm.

the class CharacterCodingExceptionTest method testConstructor.

public void testConstructor() {
    CharacterCodingException ex = new CharacterCodingException();
    assertTrue(ex instanceof IOException);
    assertNull(ex.getCause());
    assertNull(ex.getMessage());
}
Also used : CharacterCodingException(java.nio.charset.CharacterCodingException) IOException(java.io.IOException)

Example 63 with CharacterCodingException

use of java.nio.charset.CharacterCodingException in project robovm by robovm.

the class MalformedInputExceptionTest method testConstructor.

public void testConstructor() {
    MalformedInputException ex = new MalformedInputException(3);
    assertTrue(ex instanceof CharacterCodingException);
    assertNull(ex.getCause());
    assertEquals(ex.getInputLength(), 3);
    assertTrue(ex.getMessage().indexOf("3") != -1);
    ex = new MalformedInputException(-3);
    assertNull(ex.getCause());
    assertEquals(ex.getInputLength(), -3);
    assertTrue(ex.getMessage().indexOf("-3") != -1);
    ex = new MalformedInputException(0);
    assertNull(ex.getCause());
    assertEquals(ex.getInputLength(), 0);
    assertTrue(ex.getMessage().indexOf("0") != -1);
}
Also used : MalformedInputException(java.nio.charset.MalformedInputException) CharacterCodingException(java.nio.charset.CharacterCodingException)

Example 64 with CharacterCodingException

use of java.nio.charset.CharacterCodingException in project robovm by robovm.

the class UnmappableCharacterExceptionTest method testConstructor.

public void testConstructor() {
    UnmappableCharacterException ex = new UnmappableCharacterException(3);
    assertTrue(ex instanceof CharacterCodingException);
    assertNull(ex.getCause());
    assertEquals(ex.getInputLength(), 3);
    assertTrue(ex.getMessage().indexOf("3") != -1);
    ex = new UnmappableCharacterException(-3);
    assertNull(ex.getCause());
    assertEquals(ex.getInputLength(), -3);
    assertTrue(ex.getMessage().indexOf("-3") != -1);
    ex = new UnmappableCharacterException(0);
    assertNull(ex.getCause());
    assertEquals(ex.getInputLength(), 0);
    assertTrue(ex.getMessage().indexOf("0") != -1);
}
Also used : UnmappableCharacterException(java.nio.charset.UnmappableCharacterException) CharacterCodingException(java.nio.charset.CharacterCodingException)

Example 65 with CharacterCodingException

use of java.nio.charset.CharacterCodingException in project brisk by riptano.

the class SchemaManagerService method buildTable.

private Table buildTable(CfDef cfDef) {
    Table table = new Table();
    table.setDbName(cfDef.keyspace);
    table.setTableName(cfDef.name);
    table.setTableType(TableType.EXTERNAL_TABLE.toString());
    table.putToParameters("EXTERNAL", "TRUE");
    table.putToParameters("cassandra.ks.name", cfDef.keyspace);
    table.putToParameters("cassandra.cf.name", cfDef.name);
    table.putToParameters("cassandra.slice.predicate.size", "100");
    table.putToParameters("storage_handler", "org.apache.hadoop.hive.cassandra.CassandraStorageHandler");
    table.setPartitionKeys(new ArrayList<FieldSchema>());
    // cassandra.column.mapping
    StorageDescriptor sd = new StorageDescriptor();
    sd.setInputFormat("org.apache.hadoop.hive.cassandra.input.HiveCassandraStandardColumnInputFormat");
    sd.setOutputFormat("org.apache.hadoop.hive.cassandra.output.HiveCassandraOutputFormat");
    sd.setParameters(new HashMap<String, String>());
    try {
        sd.setLocation(warehouse.getDefaultTablePath(cfDef.keyspace, cfDef.name).toString());
    } catch (MetaException me) {
        log.error("could not build path information correctly", me);
    }
    SerDeInfo serde = new SerDeInfo();
    serde.setSerializationLib("org.apache.hadoop.hive.cassandra.serde.CassandraColumnSerDe");
    serde.putToParameters("serialization.format", "1");
    StringBuilder mapping = new StringBuilder();
    StringBuilder validator = new StringBuilder();
    try {
        CFMetaData cfm = CFMetaData.fromThrift(cfDef);
        AbstractType keyValidator = cfDef.key_validation_class != null ? TypeParser.parse(cfDef.key_validation_class) : BytesType.instance;
        addTypeToStorageDescriptor(sd, ByteBufferUtil.bytes("row_key"), keyValidator, keyValidator);
        mapping.append(":key");
        validator.append(keyValidator.toString());
        for (ColumnDef column : cfDef.getColumn_metadata()) {
            addTypeToStorageDescriptor(sd, column.name, TypeParser.parse(cfDef.comparator_type), TypeParser.parse(column.getValidation_class()));
            try {
                mapping.append(",");
                mapping.append(ByteBufferUtil.string(column.name));
                validator.append(",");
                validator.append(column.getValidation_class());
            } catch (CharacterCodingException e) {
                log.error("could not build column mapping correctly", e);
            }
        }
        serde.putToParameters("cassandra.columns.mapping", mapping.toString());
        serde.putToParameters("cassandra.cf.validatorType", validator.toString());
        sd.setSerdeInfo(serde);
    } catch (ConfigurationException ce) {
        throw new CassandraHiveMetaStoreException("Problem converting comparator type: " + cfDef.comparator_type, ce);
    } catch (InvalidRequestException ire) {
        throw new CassandraHiveMetaStoreException("Problem parsing CfDef: " + cfDef.name, ire);
    }
    table.setSd(sd);
    if (log.isDebugEnabled())
        log.debug("constructed table for CF:{} {}", cfDef.name, table.toString());
    return table;
}
Also used : Table(org.apache.hadoop.hive.metastore.api.Table) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) SerDeInfo(org.apache.hadoop.hive.metastore.api.SerDeInfo) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) ColumnDef(org.apache.cassandra.thrift.ColumnDef) CharacterCodingException(java.nio.charset.CharacterCodingException) ConfigurationException(org.apache.cassandra.config.ConfigurationException) AbstractType(org.apache.cassandra.db.marshal.AbstractType) CFMetaData(org.apache.cassandra.config.CFMetaData) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Aggregations

CharacterCodingException (java.nio.charset.CharacterCodingException)90 ByteBuffer (java.nio.ByteBuffer)46 CharsetEncoder (java.nio.charset.CharsetEncoder)16 CharBuffer (java.nio.CharBuffer)15 IOException (java.io.IOException)14 CoderResult (java.nio.charset.CoderResult)13 CharsetDecoder (java.nio.charset.CharsetDecoder)11 Charset (java.nio.charset.Charset)10 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)8 IllegalCharsetNameException (java.nio.charset.IllegalCharsetNameException)6 UnmappableCharacterException (java.nio.charset.UnmappableCharacterException)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 InputStream (java.io.InputStream)5 CoreException (org.eclipse.core.runtime.CoreException)5 IStatus (org.eclipse.core.runtime.IStatus)5 Status (org.eclipse.core.runtime.Status)5 HumanReadableException (com.facebook.buck.util.HumanReadableException)4 SequenceInputStream (java.io.SequenceInputStream)4 Path (java.nio.file.Path)4 Date (java.util.Date)4