Java Code Examples for org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory#writableStringObjectInspector()

The following examples show how to use org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory#writableStringObjectInspector() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MapURLUDF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException {
    if (argOIs.length != 3 && argOIs.length != 4) {
        throw new UDFArgumentException("_FUNC_ takes 3 or 4 arguments: " + argOIs.length);
    }
    if (argOIs.length == 4) {
        String opts = HiveUtils.getConstString(argOIs[3]);
        processOptions(opts);
    }

    this.latOI = HiveUtils.asDoubleCompatibleOI(argOIs[0]);
    this.lonOI = HiveUtils.asDoubleCompatibleOI(argOIs[1]);
    this.zoomOI = HiveUtils.asIntegerOI(argOIs[2]);

    this.result = new Text();
    return PrimitiveObjectInspectorFactory.writableStringObjectInspector;
}
 
Example 2
Source File: FromJsonUDFTest.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Test
public void testDoubleArray() throws Exception {
    FromJsonUDF udf = new FromJsonUDF();

    String json = "[0.1,1.1,2.2]";
    String types = "array<double>";
    List<Double> expected = Arrays.asList(0.1d, 1.1d, 2.2d);

    ObjectInspector[] argOIs = new ObjectInspector[] {
            PrimitiveObjectInspectorFactory.writableStringObjectInspector,
            HiveUtils.getConstStringObjectInspector(types)};
    DeferredObject[] args =
            new DeferredObject[] {new GenericUDF.DeferredJavaObject(new Text(json)), null};

    udf.initialize(argOIs);
    Object result = udf.evaluate(args);

    Assert.assertEquals(expected, result);

    udf.close();
}
 
Example 3
Source File: ToJsonUDF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException {
    if (argOIs.length != 1 && argOIs.length != 2) {
        throw new UDFArgumentException(
            "from_json takes one or two arguments: " + argOIs.length);
    }

    this.objOI = argOIs[0];
    if (argOIs.length == 2) {
        final ObjectInspector argOI1 = argOIs[1];
        if (HiveUtils.isConstString(argOI1)) {
            String names = HiveUtils.getConstString(argOI1);
            this.columnNames = ArrayUtils.asKryoSerializableList(names.split(","));
        } else if (HiveUtils.isConstStringListOI(argOI1)) {
            this.columnNames =
                    ArrayUtils.asKryoSerializableList(HiveUtils.getConstStringArray(argOI1));
        } else {
            throw new UDFArgumentException("Expected `const array<string>` or `const string`"
                    + " but got an unexpected OI type for the third argument: " + argOI1);
        }
    }

    return PrimitiveObjectInspectorFactory.writableStringObjectInspector;
}
 
Example 4
Source File: FromJsonUDFTest.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testPersonStruct() throws Exception {
    FromJsonUDF udf = new FromJsonUDF();

    String json = "{ \"person\" : { \"name\" : \"makoto\" , \"age\" : 37 } }";
    String types = "struct<name:string,age:int>";

    ObjectInspector[] argOIs = new ObjectInspector[] {
            PrimitiveObjectInspectorFactory.writableStringObjectInspector,
            HiveUtils.getConstStringObjectInspector(types),
            HiveUtils.getConstStringObjectInspector("person")};
    DeferredObject[] args =
            new DeferredObject[] {new GenericUDF.DeferredJavaObject(new Text(json)), null};

    udf.initialize(argOIs);
    List<Object> result = (List<Object>) udf.evaluate(args);

    Assert.assertEquals(2, result.size());
    Assert.assertEquals("makoto", result.get(0));
    Assert.assertEquals(37, result.get(1));

    udf.close();
}
 
Example 5
Source File: ArrayWritableObjectInspector.java    From indexr with Apache License 2.0 6 votes vote down vote up
private ObjectInspector getObjectInspector(final TypeInfo typeInfo) {
    if (typeInfo.equals(TypeInfoFactory.doubleTypeInfo)) {
        return PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
    } else if (typeInfo.equals(TypeInfoFactory.booleanTypeInfo)) {
        return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector;
    } else if (typeInfo.equals(TypeInfoFactory.floatTypeInfo)) {
        return PrimitiveObjectInspectorFactory.writableFloatObjectInspector;
    } else if (typeInfo.equals(TypeInfoFactory.intTypeInfo)) {
        return PrimitiveObjectInspectorFactory.writableIntObjectInspector;
    } else if (typeInfo.equals(TypeInfoFactory.longTypeInfo)) {
        return PrimitiveObjectInspectorFactory.writableLongObjectInspector;
    } else if (typeInfo.equals(TypeInfoFactory.stringTypeInfo)) {
        return PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    } else if (typeInfo.equals(TypeInfoFactory.timestampTypeInfo)) {
        return PrimitiveObjectInspectorFactory.writableTimestampObjectInspector;
    } else if (typeInfo.equals(TypeInfoFactory.dateTypeInfo)) {
        return PrimitiveObjectInspectorFactory.writableDateObjectInspector;
    } else {
        throw new UnsupportedOperationException("Unknown field type: " + typeInfo);
    }
}
 
Example 6
Source File: KuromojiUDFTest.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Test
public void testEvaluateLongRow() throws IOException, HiveException {
    KuromojiUDF udf = new KuromojiUDF();
    ObjectInspector[] argOIs = new ObjectInspector[1];
    // line
    argOIs[0] = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    udf.initialize(argOIs);

    DeferredObject[] args = new DeferredObject[1];
    args[0] = new DeferredObject() {
        public Text get() throws HiveException {
            return new Text(
                "商品の購入・詳細(サイズ、画像)は商品名をクリックしてください![L.B CANDY STOCK]フラワービジューベアドレス[L.B DAILY STOCK]ボーダーニットトップス[L.B DAILY STOCK]ボーダーロングニットOP[L.B DAILY STOCK]ロゴトートBAG[L.B DAILY STOCK]裏毛ロゴプリントプルオーバー【TVドラマ着用】アンゴラワッフルカーディガン【TVドラマ着用】グラフィティーバックリボンワンピース【TVドラマ着用】ボーダーハイネックトップス【TVドラマ着用】レオパードミッドカーフスカート【セットアップ対応商品】起毛ニットスカート【セットアップ対応商品】起毛ニットプルオーバー2wayサングラス33ナンバーリングニット3Dショルダーフレアードレス3周年スリッパ3周年ラグマット3周年ロックグラスキャンドルLily Brown 2015年 福袋MIXニットプルオーバーPeckhamロゴニットアンゴラジャガードプルオーバーアンゴラタートルアンゴラチュニックアンゴラニットカーディガンアンゴラニットプルオーバーアンゴラフレアワンピースアンゴラロングカーディガンアンゴラワッフルカーディガンヴィンテージファー付コートヴィンテージボーダーニットヴィンテージレースハイネックトップスヴィンテージレースブラウスウエストシースルーボーダーワンピースオーガンジーラインフレアスカートオープンショルダーニットトップスオフショルシャーリングワンピースオフショルニットオフショルニットプルオーバーオフショルボーダーロンパースオフショルワイドコンビネゾンオルテガ柄ニットプルオーバーカシュクールオフショルワンピースカットアシンメトリードレスカットサテンプリーツフレアースカートカラースーパーハイウェストスキニーカラーブロックドレスカラーブロックニットチュニックギャザーフレアスカートキラキラストライプタイトスカートキラキラストライプドレスキルティングファーコートグラデーションベアドレスグラデーションラウンドサングラスグラフティーオフショルトップスグラフティーキュロットグリッターリボンヘアゴムクロップドブラウスケーブルハイウエストスカートコーデュロイ×スエードパネルスカートコーデュロイタイトスカートゴールドバックルベルト付スカートゴシックヒールショートブーツゴシック柄ニットワンピコンビスタジャンサイドステッチボーイズデニムパンツサスペつきショートパンツサスペンダー付プリーツロングスカートシャーリングタイトスカートジャガードタックワンピーススエードフリルフラワーパンツスエード裏毛肩空きトップススクエアショルダーBAGスクエアバックルショルダースクエアミニバッグストーンビーチサンダルストライプサスペ付きスキニーストライプバックスリットシャツスライバーシャギーコートタートル×レースタイトスカートタートルニットプルオーバータイトジャンパースカートダブルクロスチュールフレアスカートダブルストラップパンプスダブルハートリングダブルフェイスチェックストールチェーンコンビビジューネックレスチェーンコンビビジューピアスチェーンコンビビジューブレスチェーンツバ広HATチェーンビジューピアスチェックニットプルオーバーチェックネルミディアムスカートチェック柄スキニーパンツチュールコンビアシメトップスデニムフレアースカートドットオフショルフリルブラウスドットジャガードドレスドットニットプルオーバードットレーストップスニット×オーガンジースカートセットニットキャミソールワンピースニットスヌードパールコンビフープピアスハイウエストショートデニムハイウエストタイトスカートハイウエストデニムショートパンツハイウエストプリーツスカートハイウエストミッドカーフスカートハイゲージタートルニットハイゲージラインニットハイネック切り替えスウェットバタフライネックレスバタフライミニピアスバタフライリングバックタンクリブワンピースバックリボンスキニーデニムパンツバックリボン深Vワンピースビジューストラップサンダルビスチェコンビオフショルブラウスブークレジャガードニットフェイクムートンショートコートフェレットカーディガンフェレットビックタートルニットブラウジングクルーブラウスプリーツブラウスフリルニットプルオーバーフリンジニットプルオーバーフレアニットスカートブロウ型サングラスベーシックフェレットプルオーバーベルト付ガウチョパンツベルト付ショートパンツベルト付タックスカートベルト付タックパンツベルベットインヒールパンプスベロアウェッジパンプスベロアミッドカーフワンピースベロアワンピースベロア風ニットカーディガンボア付コートボーダーVネックTシャツボーダーオフショルカットソーボーダーカットソーワンピースボーダータイトカットソーボーダートップスボーダートップス×スカートセットボストンメガネマオカラーシャツニットセットミックスニットプルオーバーミッドカーフ丈ポンチスカートミリタリーギャザーショートパンツメッシュハイネックトップスメルトンPコートメルトンダッフルコートメルトンダブルコートモヘアニットカーディガンモヘアニットタートルユリ柄プリーツフレアースカートライダースデニムジャケットライナー付チェスターコートラッフルプリーツブラウスラメジャガードハイゲージニットリブニットワンピリボン×パールバレッタリボンバレッタリボンベルトハイウエストパンツリリー刺繍開襟ブラウスレースビスチェローファーサボロゴニットキャップロゴ刺繍ニットワッチロングニットガウンワッフルアンゴラプルオーバーワンショルダワーワンピース光沢ラメニットカーディガン刺繍シフォンブラウス台形ミニスカート配色ニットプルオーバー裏毛プルオーバー×オーガンジースカートセット");
        }

        @Override
        public void prepare(int arg) throws HiveException {}
    };
    @SuppressWarnings("unchecked")
    List<Text> tokens = (List<Text>) udf.evaluate(args);
    Assert.assertNotNull(tokens);
    Assert.assertEquals(182, tokens.size());
    udf.close();
}
 
Example 7
Source File: KuromojiUDFTest.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Test
public void testEvaluateOneRow() throws IOException, HiveException {
    KuromojiUDF udf = new KuromojiUDF();
    ObjectInspector[] argOIs = new ObjectInspector[1];
    // line
    argOIs[0] = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    udf.initialize(argOIs);

    DeferredObject[] args = new DeferredObject[1];
    args[0] = new DeferredObject() {
        public Text get() throws HiveException {
            return new Text("クロモジのJapaneseAnalyzerを使ってみる。テスト。");
        }

        @Override
        public void prepare(int arg) throws HiveException {}
    };
    @SuppressWarnings("unchecked")
    List<Text> tokens = (List<Text>) udf.evaluate(args);
    Assert.assertNotNull(tokens);
    Assert.assertEquals(5, tokens.size());
    udf.close();
}
 
Example 8
Source File: TreeExportUDF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException {
    final int argLen = argOIs.length;
    if (argLen < 2 || argLen > 4) {
        showHelp("tree_export UDF takes 2~4 arguments: " + argLen);
    }

    this.modelOI = HiveUtils.asStringOI(argOIs, 0);

    String options = HiveUtils.getConstString(argOIs, 1);
    processOptions(options);

    if (argLen >= 3) {
        this.featureNamesOI = HiveUtils.asListOI(argOIs, 2);
        if (!HiveUtils.isStringOI(featureNamesOI.getListElementObjectInspector())) {
            throw new UDFArgumentException("_FUNC_ expected array<string> for featureNames: "
                    + featureNamesOI.getTypeName());
        }
        if (argLen == 4) {
            this.classNamesOI = HiveUtils.asListOI(argOIs, 3);
            if (!HiveUtils.isStringOI(classNamesOI.getListElementObjectInspector())) {
                throw new UDFArgumentException("_FUNC_ expected array<string> for classNames: "
                        + classNamesOI.getTypeName());
            }
        }
    }

    return PrimitiveObjectInspectorFactory.writableStringObjectInspector;
}
 
Example 9
Source File: OrcLazyObjectInspectorUtils.java    From hive-dwrf with Apache License 2.0 5 votes vote down vote up
public static ObjectInspector createWritableObjectInspector(int columnId,
                                             List<OrcProto.Type> types){
  OrcProto.Type type = types.get(columnId);
  switch (type.getKind()) {
    case FLOAT:
      return PrimitiveObjectInspectorFactory.writableFloatObjectInspector;
    case DOUBLE:
      return PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
    case BOOLEAN:
      return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector;
    case BYTE:
      return PrimitiveObjectInspectorFactory.writableByteObjectInspector;
    case SHORT:
      return PrimitiveObjectInspectorFactory.writableShortObjectInspector;
    case INT:
      return PrimitiveObjectInspectorFactory.writableIntObjectInspector;
    case LONG:
      return PrimitiveObjectInspectorFactory.writableLongObjectInspector;
    case BINARY:
      return PrimitiveObjectInspectorFactory.writableBinaryObjectInspector;
    case STRING:
      return PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    case TIMESTAMP:
      return PrimitiveObjectInspectorFactory.javaTimestampObjectInspector;
    case STRUCT:
      return new OrcStruct.OrcStructInspector(columnId, types);
    case UNION:
      return new OrcUnion.OrcUnionObjectInspector(columnId, types);
    case MAP:
      return new OrcStruct.OrcMapObjectInspector(columnId, types);
    case LIST:
      return new OrcStruct.OrcListObjectInspector(columnId, types);
    default:
      throw new UnsupportedOperationException("Unknown type " +
        type.getKind());
  }
}
 
Example 10
Source File: InflateUDF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException {
    if (argOIs.length != 1) {
        throw new UDFArgumentException("_FUNC_ takes exactly 1 argument");
    }
    this.binaryOI = HiveUtils.asBinaryOI(argOIs[0]);

    return PrimitiveObjectInspectorFactory.writableStringObjectInspector;
}
 
Example 11
Source File: Base91UDF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException {
    if (argOIs.length != 1) {
        throw new UDFArgumentException("_FUNC_ takes exactly 1 argument");
    }
    this.binaryOI = HiveUtils.asBinaryOI(argOIs[0]);

    return PrimitiveObjectInspectorFactory.writableStringObjectInspector;
}
 
Example 12
Source File: FeatureUDFTest.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Test
public void testTextDouble() throws Exception {
    ObjectInspector featureOI = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    ObjectInspector weightOI = PrimitiveObjectInspectorFactory.javaDoubleObjectInspector;
    udf.initialize(new ObjectInspector[] {featureOI, weightOI});

    Text ret = udf.evaluate(new GenericUDF.DeferredObject[] {
            new DeferredJavaObject(new Text("f1")), new DeferredJavaObject(2.5d)});

    Assert.assertEquals("f1:2.5", ret.toString());
}
 
Example 13
Source File: FeatureUDFTest.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Test
public void testTextDoubleWritable() throws Exception {
    ObjectInspector featureOI = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    ObjectInspector weightOI = PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
    udf.initialize(new ObjectInspector[] {featureOI, weightOI});

    Text ret = udf.evaluate(
        new GenericUDF.DeferredObject[] {new DeferredJavaObject(new Text("f1")),
                new DeferredJavaObject(new DoubleWritable(2.5d))});

    Assert.assertEquals("f1:2.5", ret.toString());
}
 
Example 14
Source File: UDFArrayJoin.java    From hive-third-functions with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    // Check if two arguments were passed
    if (arguments.length > MAX_ARG_COUNT || arguments.length < MIN_ARG_COUNT) {
        throw new UDFArgumentLengthException(
                "The function array_join(array, delimiter) or array_join(array, delimiter, null_replacement) takes exactly "
                        + MIN_ARG_COUNT + " or " + MAX_ARG_COUNT + " arguments.");
    }

    // Check if ARRAY_IDX argument is of category LIST
    if (!arguments[ARRAY_IDX].getCategory().equals(ObjectInspector.Category.LIST)) {
        throw new UDFArgumentTypeException(ARRAY_IDX,
                "\"" + org.apache.hadoop.hive.serde.serdeConstants.LIST_TYPE_NAME + "\" "
                        + "expected at function array_join, but "
                        + "\"" + arguments[ARRAY_IDX].getTypeName() + "\" "
                        + "is found");
    }

    arrayOI = (ListObjectInspector) arguments[ARRAY_IDX];
    arrayElementOI = arrayOI.getListElementObjectInspector();

    delimiterOI = arguments[DELIMITER_IDX];
    delimiterConvert = ObjectInspectorConverters.getConverter(delimiterOI, PrimitiveObjectInspectorFactory.writableStringObjectInspector);
    if (arguments.length == MAX_ARG_COUNT) {
        nullReplaceOI = arguments[NULL_REPLACE_IDX];
        nullReplaceConvert = ObjectInspectorConverters.getConverter(nullReplaceOI, PrimitiveObjectInspectorFactory.writableStringObjectInspector);
    }

    result = new Text();

    return PrimitiveObjectInspectorFactory.writableStringObjectInspector;
}
 
Example 15
Source File: KuromojiUDFTest.java    From incubator-hivemall with Apache License 2.0 4 votes vote down vote up
@Test
public void testEvaluateUserDictArray() throws IOException, HiveException {
    KuromojiUDF udf = new KuromojiUDF();
    ObjectInspector[] argOIs = new ObjectInspector[5];
    // line
    argOIs[0] = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    // mode
    PrimitiveTypeInfo stringType = new PrimitiveTypeInfo();
    stringType.setTypeName("string");
    argOIs[1] = PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(
        stringType, null);
    // stopWords
    argOIs[2] = ObjectInspectorFactory.getStandardConstantListObjectInspector(
        PrimitiveObjectInspectorFactory.writableStringObjectInspector, null);
    // stopTags
    argOIs[3] = ObjectInspectorFactory.getStandardConstantListObjectInspector(
        PrimitiveObjectInspectorFactory.writableStringObjectInspector, null);
    // userDictArray (from https://raw.githubusercontent.com/atilika/kuromoji/909fd6b32bf4e9dc86b7599de5c9b50ca8f004a1/kuromoji-core/src/test/resources/userdict.txt)
    List<String> userDict = new ArrayList<String>();
    userDict.add("日本経済新聞,日本 経済 新聞,ニホン ケイザイ シンブン,カスタム名詞");
    userDict.add("関西国際空港,関西 国際 空港,カンサイ コクサイ クウコウ,テスト名詞");
    argOIs[4] = ObjectInspectorFactory.getStandardConstantListObjectInspector(
        PrimitiveObjectInspectorFactory.writableStringObjectInspector, userDict);
    udf.initialize(argOIs);

    DeferredObject[] args = new DeferredObject[1];
    args[0] = new DeferredObject() {
        public Text get() throws HiveException {
            return new Text("日本経済新聞。");
        }

        @Override
        public void prepare(int arg) throws HiveException {}
    };

    @SuppressWarnings("unchecked")
    List<Text> tokens = (List<Text>) udf.evaluate(args);

    Assert.assertNotNull(tokens);
    Assert.assertEquals(3, tokens.size());

    udf.close();
}
 
Example 16
Source File: KuromojiUDFTest.java    From incubator-hivemall with Apache License 2.0 4 votes vote down vote up
@Test
public void testEvaluateUserDictURL() throws IOException, HiveException {
    KuromojiUDF udf = new KuromojiUDF();
    ObjectInspector[] argOIs = new ObjectInspector[5];
    // line
    argOIs[0] = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    // mode
    PrimitiveTypeInfo stringType = new PrimitiveTypeInfo();
    stringType.setTypeName("string");
    argOIs[1] = PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(
        stringType, null);
    // stopWords
    argOIs[2] = ObjectInspectorFactory.getStandardConstantListObjectInspector(
        PrimitiveObjectInspectorFactory.writableStringObjectInspector, null);
    // stopTags
    argOIs[3] = ObjectInspectorFactory.getStandardConstantListObjectInspector(
        PrimitiveObjectInspectorFactory.writableStringObjectInspector, null);
    // userDictUrl (Kuromoji official sample user defined dict on GitHub)
    // e.g., "日本経済新聞" will be "日本", "経済", and "新聞"
    argOIs[4] = PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(
        stringType, new Text(
            "https://raw.githubusercontent.com/atilika/kuromoji/909fd6b32bf4e9dc86b7599de5c9b50ca8f004a1/kuromoji-core/src/test/resources/userdict.txt"));
    udf.initialize(argOIs);

    DeferredObject[] args = new DeferredObject[1];
    args[0] = new DeferredObject() {
        public Text get() throws HiveException {
            return new Text("クロモジのJapaneseAnalyzerを使ってみる。日本経済新聞。");
        }

        @Override
        public void prepare(int arg) throws HiveException {}
    };

    @SuppressWarnings("unchecked")
    List<Text> tokens = (List<Text>) udf.evaluate(args);

    Assert.assertNotNull(tokens);
    Assert.assertEquals(7, tokens.size());

    udf.close();
}
 
Example 17
Source File: GeneralRegressorUDTFTest.java    From incubator-hivemall with Apache License 2.0 4 votes vote down vote up
@Test
public void testTextFeature() throws Exception {
    List<Text> x = Arrays.asList(new Text("1:-2"), new Text("2:-1"));
    ObjectInspector featureOI = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    testFeature(x, featureOI, Text.class, String.class);
}
 
Example 18
Source File: MDSObjectInspectorFactory.java    From multiple-dimension-spread with Apache License 2.0 4 votes vote down vote up
public static ObjectInspector craeteObjectInspectorFromTypeInfo( final TypeInfo typeInfo ){
  switch ( typeInfo.getCategory() ){
    case STRUCT:
      return new MDSStructObjectInspector( (StructTypeInfo)typeInfo );
    case MAP:
      return new MDSMapObjectInspector( (MapTypeInfo)typeInfo );
    case LIST:
      return new MDSListObjectInspector( (ListTypeInfo)typeInfo );
    case UNION:
      UnionTypeInfo unionTypeInfo = (UnionTypeInfo)typeInfo;
      List<ObjectInspector> unionList = new ArrayList<ObjectInspector>();
      for( TypeInfo childTypeInfo : unionTypeInfo.getAllUnionObjectTypeInfos() ){
        unionList.add( craeteObjectInspectorFromTypeInfo( childTypeInfo ) );
      }
      return ObjectInspectorFactory.getStandardUnionObjectInspector( unionList );
    case PRIMITIVE:
      PrimitiveTypeInfo primitiveTypeInfo = (PrimitiveTypeInfo)typeInfo;
      switch( primitiveTypeInfo.getPrimitiveCategory() ){
        case STRING:
          return PrimitiveObjectInspectorFactory.writableStringObjectInspector;
        case BINARY:
          return PrimitiveObjectInspectorFactory.writableBinaryObjectInspector;
        case BOOLEAN:
          return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector;
        case BYTE:
          return PrimitiveObjectInspectorFactory.writableByteObjectInspector;
        case DOUBLE:
          return PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
        case FLOAT:
          return PrimitiveObjectInspectorFactory.writableFloatObjectInspector;
        case INT:
          return PrimitiveObjectInspectorFactory.writableIntObjectInspector;
        case LONG:
          return PrimitiveObjectInspectorFactory.writableLongObjectInspector;
        case SHORT:
          return PrimitiveObjectInspectorFactory.writableShortObjectInspector;

        case DATE:
        case DECIMAL:
        case TIMESTAMP:
        case VOID:
        default:
        throw new UnsupportedOperationException( "Unknown primitive category " + primitiveTypeInfo.getPrimitiveCategory() );
      }
    default:
      throw new UnsupportedOperationException( "Unknown category " + typeInfo.getCategory() );
  }
}
 
Example 19
Source File: OrcLazyObjectInspectorUtils.java    From hive-dwrf with Apache License 2.0 4 votes vote down vote up
public static ObjectInspector createWritableObjectInspector(TypeInfo info) {
  switch (info.getCategory()) {
    case PRIMITIVE:
      switch (((PrimitiveTypeInfo) info).getPrimitiveCategory()) {
        case FLOAT:
          return PrimitiveObjectInspectorFactory.writableFloatObjectInspector;
        case DOUBLE:
          return PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
        case BOOLEAN:
          return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector;
        case BYTE:
          return PrimitiveObjectInspectorFactory.writableByteObjectInspector;
        case SHORT:
          return PrimitiveObjectInspectorFactory.writableShortObjectInspector;
        case INT:
          return PrimitiveObjectInspectorFactory.writableIntObjectInspector;
        case LONG:
          return PrimitiveObjectInspectorFactory.writableLongObjectInspector;
        case BINARY:
          return PrimitiveObjectInspectorFactory.writableBinaryObjectInspector;
        case STRING:
          return PrimitiveObjectInspectorFactory.writableStringObjectInspector;
        case TIMESTAMP:
          return PrimitiveObjectInspectorFactory.javaTimestampObjectInspector;
        default:
          throw new IllegalArgumentException("Unknown primitive type " +
            ((PrimitiveTypeInfo) info).getPrimitiveCategory());
      }
    case STRUCT:
      return new OrcStruct.OrcStructInspector((StructTypeInfo) info);
    case UNION:
      return new OrcUnion.OrcUnionObjectInspector((UnionTypeInfo) info);
    case MAP:
      return new OrcStruct.OrcMapObjectInspector((MapTypeInfo) info);
    case LIST:
      return new OrcStruct.OrcListObjectInspector((ListTypeInfo) info);
    default:
      throw new IllegalArgumentException("Unknown type " +
        info.getCategory());
  }
}
 
Example 20
Source File: GeneralClassifierUDTFTest.java    From incubator-hivemall with Apache License 2.0 4 votes vote down vote up
@Test
public void testTextFeature() throws Exception {
    List<Text> x = Arrays.asList(new Text("1:-2"), new Text("2:-1"));
    ObjectInspector featureOI = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    testFeature(x, featureOI, Text.class, String.class);
}