<commit_before>/*
 * Copyright 2013 the original author or authors.
 *
 * Licensed 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.elasticsearch.hadoop.hive;

import java.io.IOException;
import java.util.Properties;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hive.ql.exec.FileSinkOperator.RecordWriter;
import org.apache.hadoop.hive.ql.io.HiveOutputFormat;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.Reporter;
import org.apache.hadoop.util.Progressable;
import org.elasticsearch.hadoop.mr.ESOutputFormat;

/**
 * Hive specific OutputFormat.
 */
@SuppressWarnings("rawtypes")
public class ESHiveOutputFormat extends ESOutputFormat implements HiveOutputFormat {

    static class ESHiveRecordWriter extends ESOutputFormat.ESRecordWriter implements RecordWriter {

        public ESHiveRecordWriter(Configuration cfg) {
            super(cfg);
        }

        @Override
        public void write(Writable w) throws IOException {
            if (w instanceof HiveEntityWritable) {
                HiveEntityWritable hew = ((HiveEntityWritable) w);
                client.writeToIndex(hew.getBytes(), hew.getLength(), hew.getId());
            }
            else {
                throw new IllegalArgumentException(String.format("Unexpected type; expected [%s], received [%s]", HiveEntityWritable.class, w));
            }
        }

        @Override
        public void close(boolean abort) throws IOException {
            // TODO: check whether a proper Reporter can be passed in
            super.close((Reporter) null);
        }
    }

    @Override
    public RecordWriter getHiveRecordWriter(JobConf jc, Path finalOutPath, Class valueClass, boolean isCompressed, Properties tableProperties, Progressable progress) {<commit_msg>update Hive to use concurrent writes relates to #106<commit_after>/*
 * Copyright 2013 the original author or authors.
 *
 * Licensed 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.elasticsearch.hadoop.hive;

import java.io.IOException;
import java.util.Properties;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hive.ql.exec.FileSinkOperator.RecordWriter;
import org.apache.hadoop.hive.ql.io.HiveOutputFormat;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.Reporter;
import org.apache.hadoop.util.Progressable;
import org.elasticsearch.hadoop.mr.ESOutputFormat;

/**
 * Hive specific OutputFormat.
 */
@SuppressWarnings("rawtypes")
public class ESHiveOutputFormat extends ESOutputFormat implements HiveOutputFormat {

    static class ESHiveRecordWriter extends ESOutputFormat.ESRecordWriter implements RecordWriter {

        public ESHiveRecordWriter(Configuration cfg) {
            super(cfg);
        }

        @Override
        public void write(Writable w) throws IOException {
            if (!initialized) {
                initialized = true;
                init();
            }

            if (w instanceof HiveEntityWritable) {
                HiveEntityWritable hew = ((HiveEntityWritable) w);
                client.writeToIndex(hew.getBytes(), hew.getLength(), hew.getId());
            }
            else {
                throw new IllegalArgumentException(String.format("Unexpected type; expected [%s], received [%s]", HiveEntityWritable.class, w));
            }
        }

        @Override
        public void close(boolean abort) throws IOException {
            // TODO: check whether a proper Reporter can be passed in
            super.close((Reporter) null);
        }
    }

    @Override
    public RecordWriter getHiveRecordWriter(JobConf jc, Path finalOutPath, Class valueClass, boolean isCompressed, Properties tableProperties, Progressable progress) {
{'fraction_non_alphanumeric': 0.08469387755102041, 'fraction_numerical': 0.0038775510204081634, 'mean_word_length': 3.2177280550774525, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1694465', 'n_tokens_mistral': 1280, 'n_tokens_neox': 1258, 'n_words': 403}