<commit_before>/*
 * Copyright © 2016 <NAME>, Inc.
 *
 * 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.
 */

angular.module(`${PKG.name}.feature.experimental`)
  .controller('ComplexSchemaController', function(avsc) {
    var schema = '{"type":"record","name":"rec","fields":[{"name":"bool_field","type":["boolean","null"]},{"name":"int_field","type":"int"},{"name":"long_field","type":"long"},{"name":"float_field","type":"float"},{"name":"double_field","type":"double"},{"name":"bytes_field","type":"bytes"},{"name":"array_field","type":{"type":"array","items":["string","null"]}},{"name":"enum_field","type":{"type":"enum","symbols":["Monday","Tuesday","Wednesday"]}},{"name":"union_field","type":["double","float","bytes"]},{"name":"map_field","type":{"type":"map","keys":["string","null"],"values":["int","null"]}},{"name":"record_field","type":[{"type":"record","name":"rec1","fields":[{"name":"x","type":["int","null"]},{"name":"y","type":["double","null"]}]},"null"]},{"name":"string_field","type":["string","null"]}]}';


    // let union = {
    //   name: 'test',
    //   type: 'record',
    //   fields: [
    //     {
    //       name: 'string_field',
    //       type: ['float', 'int']
    //     }
    //   ]
    // };
    // let parsed = avsc.parse(union, { wrapUnions: true });
    // console.log('parsed', parsed);


    let parsed = avsc.parse(schema, { wrapUnions: true }).getFields();

    angular.forEach(parsed, (field) => {
      let name = field.getName();
      let type = field.getType();

      if (type.getTypeName() === 'union:wrapped') {
        let temp = '';

        type = type.getTypes();
        angular.forEach(type, (tempType) => {
          temp = temp + tempType.getTypeName() + ' ';
        });
        type = temp;

      } else {
        type = type.getTypeName();
      }

      console.log(name + ': ' + type);
    });

    // function parseSchemaType (field) {

    // }

<commit_msg>add schema types array<commit_after>/*
 * Copyright © 2016 Cask Data, Inc.
 *
 * 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.
 */

angular.module(`${PKG.name}.feature.experimental`)
  .controller('ComplexSchemaController', function(avsc) {
    var schema = '{"type":"record","name":"rec","fields":[{"name":"bool_field","type":["boolean","null"]},{"name":"int_field","type":"int"},{"name":"long_field","type":"long"},{"name":"float_field","type":"float"},{"name":"double_field","type":"double"},{"name":"bytes_field","type":"bytes"},{"name":"array_field","type":{"type":"array","items":["string","null"]}},{"name":"enum_field","type":{"type":"enum","symbols":["Monday","Tuesday","Wednesday"]}},{"name":"union_field","type":["double","float","bytes"]},{"name":"map_field","type":{"type":"map","keys":["string","null"],"values":["int","null"]}},{"name":"record_field","type":[{"type":"record","name":"rec1","fields":[{"name":"x","type":["int","null"]},{"name":"y","type":["double","null"]}]},"null"]},{"name":"string_field","type":["string","null"]}]}';


    // let union = {
    //   name: 'test',
    //   type: 'record',
    //   fields: [
    //     {
    //       name: 'string_field',
    //       type: ['float', 'int']
    //     }
    //   ]
    // };
    // let parsed = avsc.parse(union, { wrapUnions: true });
    // console.log('parsed', parsed);

    const SCHEMA_TYPES = [
      'string',
      'int',
      'long',
      'float',
      'double',
      'boolean',
      'bytes',
      'enum',
      'array',
      'map',
      'record',
      'union'
    ];


    let parsed = avsc.parse(schema, { wrapUnions: true }).getFields();

    angular.forEach(parsed, (field) => {
      let name = field.getName();
      let type = field.getType();

      if (type.getTypeName() === 'union:wrapped') {
        let temp = '';

        type = type.getTypes();
        angular.forEach(type, (tempType) => {
          temp = temp + tempType.getTypeName() + ' ';
        });
        type = temp;

      } else {
        type = type.getTypeName();
      }

      console.log(name + ': ' + type);

      console.log(SCHEMA_TYPES);
    });

    // function parseSchemaType (field) {

    // }


{'fraction_non_alphanumeric': 0.22908949112887503, 'fraction_numerical': 0.003509456034314681, 'mean_word_length': 3.6133093525179856, 'pattern_counts': {'":': 82, '<': 4, '<?xml version=': 0, '>': 8, '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': '6816877', 'n_tokens_mistral': 1568, 'n_tokens_neox': 1503, 'n_words': 309}