blob: 1f056e27fef1538013a63496a56eb9b413259949 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.hadoop.hive.serde2.objectinspector.primitive;
import org.apache.hadoop.hive.ql.io.parquet.writable.BinaryWritable;
import org.apache.hadoop.io.Text;
import org.apache.parquet.io.api.Binary;
/**
* The ParquetStringInspector inspects a BinaryWritable to give a Text or String.
*
*/
public class ParquetStringInspector extends JavaStringObjectInspector implements SettableStringObjectInspector {
public ParquetStringInspector() {
super();
}
@Override
public Text getPrimitiveWritableObject(final Object o) {
if (o == null) {
return null;
}
if (o instanceof BinaryWritable) {
return new Text(((BinaryWritable) o).getBytes());
}
if (o instanceof Text) {
return (Text) o;
}
if (o instanceof String) {
return new Text((String) o);
}
throw new UnsupportedOperationException("Cannot inspect " + o.getClass().getCanonicalName());
}
@Override
public String getPrimitiveJavaObject(final Object o) {
if (o == null) {
return null;
}
if (o instanceof BinaryWritable) {
return ((BinaryWritable) o).getString();
}
if (o instanceof Text) {
return ((Text) o).toString();
}
if (o instanceof String) {
return (String) o;
}
throw new UnsupportedOperationException("Cannot inspect " + o.getClass().getCanonicalName());
}
@Override
public Object set(final Object o, final Text text) {
return new BinaryWritable(text == null ? null : Binary.fromReusedByteArray(text.getBytes
()));
}
@Override
public Object set(final Object o, final String string) {
return new BinaryWritable(string == null ? null : Binary.fromString(string));
}
@Override
public Object create(final Text text) {
if (text == null) {
return null;
}
return text.toString();
}
@Override
public Object create(final String string) {
return string;
}
}