<commit_before>/*
 * (C) Copyright 2015 ETH Zurich Systems Group (http://www.systems.ethz.ch/) and others.
 *
 * 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.
 *
 * Contributors:
 *     <NAME> <<EMAIL>>
 *     <NAME> <<EMAIL>>
 *     <NAME> <<EMAIL>>
 *     <NAME> <<EMAIL>>
 *     <NAME> <<EMAIL>>
 */
#include <ch_ethz_tell_Schema.h>
#include <tellstore/Record.hpp>
#include <crossbow/enum_underlying.hpp>

#include "helpers.hpp"

jlong Java_ch_ethz_tell_Schema_construct(JNIEnv*, jobject) {
    return reinterpret_cast<long>(new tell::store::Schema());
}

void Java_ch_ethz_tell_Schema_destruct(JNIEnv*, jobject, jlong self) {
    delete reinterpret_cast<tell::store::Schema*>(self);
}

jboolean Java_ch_ethz_tell_Schema_addFieldImpl(JNIEnv* env, jobject, jlong self, jshort type, jstring jname, jboolean notNull) {
    auto s = reinterpret_cast<tell::store::Schema*>(self);
    crossbow::string name = to_string(env, jname);
    uint16_t ftU = type;
    return s->addField(crossbow::from_underlying<tell::store::FieldType>(ftU), name, notNull);
}

jboolean Java_ch_ethz_tell_Schema_allNotNullImpl(JNIEnv*, jobject, jlong self) {
    auto s = reinterpret_cast<tell::store::Schema*>(self);
    return s->allNotNull();
}

namespace {
jintArray toIntArray(JNIEnv* env, const std::vector<tell::store::Field>& fields) {
    auto res = env->NewIntArray(fields.size());
    std::unique_ptr<jint[]> tmp(new jint[fields.size()]);
    for (unsigned i = 0; i < fields.size(); ++i) {
        tmp[i] = crossbow::to_underlying(fields[i].type());
    }
    env->SetIntArrayRegion(res, 0, fields.size(), tmp.get());
    return res;
}

}

jintArray Java_ch_ethz_tell_Schema_fixedSizeFieldsImpl(JNIEnv* env, jobject, jlong self) {
    auto s = reinterpret_cast<tell::store::Schema*>(self);
    return toIntArray(env, s->fixedSizeFields());
}

jintArray Java_ch_ethz_tell_Schema_variableSizedFieldsImpl(JNIEnv* env, jobject, jlong self) {
    auto s = reinterpret_cast<tell::store::Schema*>(self);
    return toIntArray(env, s->varSizeFields());
}

jshort Java_ch_ethz_tell_Schema_idOfImpl (JNIEnv* env, jobject, jlong self, jstring columnName) {
    auto s = reinterpret_cast<tell::store::Schema*>(self);
    return s->idOf(to_string(env, columnName));
}

jshort Java_ch_ethz_tell_Schema_typeOfImpl (JNIEnv* env, jobject, jlong self, jstring columName) {
    auto s = reinterpret_cast<tell::store::Schema*>(self);
    auto field = s->getFieldFromName(to_string(env, columName));
    return static_cast<short>(field.type());
}

jboolean Java_ch_ethz_tell_Schema_nullabiltyOfImpl (JNIEnv* env, jobject, jlong self, jstring columName) {
    auto s = reinterpret_cast<tell::store::Schema*>(self);
    auto field = s->getFieldFromName(to_string(env, columName));
    return field.isNotNull();
}

jobjectArray Java_ch_ethz_tell_Schema_getFieldNamesImpl (JNIEnv* env, jobject, jlong self) {
    std::vector<std::string> resultVec;
    auto s = reinterpret_cast<tell::store::Schema*>(self);
    for (auto &field: s->fixedSizeFields())
        resultVec.emplace_back(field.name().c_str());
    for (auto &field: s->varSizeFields())
        resultVec.emplace_back(field.name().c_str());

    jclass cls = env->FindClass("java/lang/String");
    jobject job = env->AllocObject(cls);
    auto result = env->NewObjectArray(resultVec.size(), cls, job);
    for (unsigned i = 0; i < resultVec.size(); ++i) {
        env->SetObjectArrayElement(result, jsize(i), jstring(resultVec[i].c_str()));
    }
    return result;
}

<commit_msg>hopefully fixed bug swith string array<commit_after>/*
 * (C) Copyright 2015 ETH Zurich Systems Group (http://www.systems.ethz.ch/) and others.
 *
 * 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.
 *
 * Contributors:
 *     <NAME> <<EMAIL>>
 *     <NAME> <<EMAIL>>
 *     <NAME> <<EMAIL>>
 *     <NAME> <<EMAIL>>
 *     <NAME> <<EMAIL>>
 */
#include <ch_ethz_tell_Schema.h>
#include <tellstore/Record.hpp>
#include <crossbow/enum_underlying.hpp>

#include "helpers.hpp"

jlong Java_ch_ethz_tell_Schema_construct(JNIEnv*, jobject) {
    return reinterpret_cast<long>(new tell::store::Schema());
}

void Java_ch_ethz_tell_Schema_destruct(JNIEnv*, jobject, jlong self) {
    delete reinterpret_cast<tell::store::Schema*>(self);
}

jboolean Java_ch_ethz_tell_Schema_addFieldImpl(JNIEnv* env, jobject, jlong self, jshort type, jstring jname, jboolean notNull) {
    auto s = reinterpret_cast<tell::store::Schema*>(self);
    crossbow::string name = to_string(env, jname);
    uint16_t ftU = type;
    return s->addField(crossbow::from_underlying<tell::store::FieldType>(ftU), name, notNull);
}

jboolean Java_ch_ethz_tell_Schema_allNotNullImpl(JNIEnv*, jobject, jlong self) {
    auto s = reinterpret_cast<tell::store::Schema*>(self);
    return s->allNotNull();
}

namespace {
jintArray toIntArray(JNIEnv* env, const std::vector<tell::store::Field>& fields) {
    auto res = env->NewIntArray(fields.size());
    std::unique_ptr<jint[]> tmp(new jint[fields.size()]);
    for (unsigned i = 0; i < fields.size(); ++i) {
        tmp[i] = crossbow::to_underlying(fields[i].type());
    }
    env->SetIntArrayRegion(res, 0, fields.size(), tmp.get());
    return res;
}

}

jintArray Java_ch_ethz_tell_Schema_fixedSizeFieldsImpl(JNIEnv* env, jobject, jlong self) {
    auto s = reinterpret_cast<tell::store::Schema*>(self);
    return toIntArray(env, s->fixedSizeFields());
}

jintArray Java_ch_ethz_tell_Schema_variableSizedFieldsImpl(JNIEnv* env, jobject, jlong self) {
    auto s = reinterpret_cast<tell::store::Schema*>(self);
    return toIntArray(env, s->varSizeFields());
}

jshort Java_ch_ethz_tell_Schema_idOfImpl (JNIEnv* env, jobject, jlong self, jstring columnName) {
    auto s = reinterpret_cast<tell::store::Schema*>(self);
    return s->idOf(to_string(env, columnName));
}

jshort Java_ch_ethz_tell_Schema_typeOfImpl (JNIEnv* env, jobject, jlong self, jstring columName) {
    auto s = reinterpret_cast<tell::store::Schema*>(self);
    auto field = s->getFieldFromName(to_string(env, columName));
    return static_cast<short>(field.type());
}

jboolean Java_ch_ethz_tell_Schema_nullabiltyOfImpl (JNIEnv* env, jobject, jlong self, jstring columName) {
    auto s = reinterpret_cast<tell::store::Schema*>(self);
    auto field = s->getFieldFromName(to_string(env, columName));
    return field.isNotNull();
}

jobjectArray Java_ch_ethz_tell_Schema_getFieldNamesImpl (JNIEnv* env, jobject, jlong self) {
    std::vector<std::string> resultVec;
    auto s = reinterpret_cast<tell::store::Schema*>(self);
    for (auto &field: s->fixedSizeFields())
        resultVec.emplace_back(field.name().c_str());
    for (auto &field: s->varSizeFields())
        resultVec.emplace_back(field.name().c_str());

    auto cls = env->FindClass("java/lang/String");
    auto init = env->NewStringUTF("");
    auto result = env->NewObjectArray(resultVec.size(), cls, init);
    for (unsigned i = 0; i < resultVec.size(); ++i) {
        env->SetObjectArrayElement(result, jsize(i), env->NewStringUTF(resultVec[i].c_str()));
    }
    return result;
}


{'fraction_non_alphanumeric': 0.14012422360248447, 'fraction_numerical': 0.003229813664596273, 'mean_word_length': 4.959289415247964, 'pattern_counts': {'":': 0, '<': 73, '<?xml version=': 0, '>': 100, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '441877', 'n_tokens_mistral': 2751, 'n_tokens_neox': 2683, 'n_words': 615}