Flatten the <code>inputSchema</code>
{@inheritDoc}
@see org.apache.gobblin.data.management.conversion.hive.converter.AbstractAvroToOrcConverter#convertSchema(org.apache.avro.Schema, org.apache.gobblin.configuration.WorkUnitState)
549762
@Override
  public Schema convertSchema(Schema inputSchema, WorkUnitState workUnit) {
    return AVRO_FLATTENER.flatten(inputSchema, false);
  }
1135257
@SuppressWarnings({ "rawtypes", "unchecked" })
  public static Schema toPangoolSchema(org.apache.avro.Schema avroSchema) {
		List<Field> fields = new ArrayList<Field>();
		for(org.apache.avro.Schema.Field avroField : avroSchema.getFields()) {
			org.apache.avro.Schema.Type type = avroField.schema().getType();
			Field pangoolField;
			switch(type){
			case INT: pangoolField = Field.create(avroField.name(),Type.INT); break;
			case LONG: pangoolField = Field.create(avroField.name(),Type.LONG); break;
			case FLOAT: pangoolField = Field.create(avroField.name(),Type.FLOAT); break;
			case DOUBLE: pangoolField = Field.create(avroField.name(),Type.DOUBLE); break;
			case BOOLEAN: pangoolField = Field.create(avroField.name(),Type.BOOLEAN); break;
			case STRING: pangoolField = Field.create(avroField.name(),Type.STRING); break;
			case BYTES:
				if (avroField.getProp(Field.METADATA_BYTES_AS_OBJECT) == null){
					pangoolField = Field.create(avroField.name(),Type.BYTES);
				} else {
					try {
					String objectClazz = avroField.getProp(Field.METADATA_OBJECT_CLASS);
					pangoolField = Field.createObject(avroField.name(),Class.forName(objectClazz));
					String serializationString = avroField.getProp(Field.METADATA_OBJECT_SERIALIZATION);
					if (serializationString != null){
							Class<? extends Serialization> ser=
		             (serializationString == null) ? null : 
			          	(Class<? extends Serialization>)Class.forName(serializationString);
							pangoolField.setObjectSerialization(ser);
					}
					
					} catch(ClassNotFoundException e) {
	          throw new PangoolRuntimeException(e);
          }
				}
				break;
			case ENUM:
				String objectClazz = avroField.getProp(Field.METADATA_OBJECT_CLASS);
				try{
					pangoolField = Field.createEnum(avroField.name(),Class.forName(objectClazz));
					} catch(ClassNotFoundException e){
						throw new PangoolRuntimeException(e);
					}
				break;
			default:
				throw new PangoolRuntimeException("Avro type:" + type + " can't be converted to Pangool Schema type");
			}
			//add properties 
			for(Map.Entry<String,String> entry : avroField.props().entrySet()){
				if (!Field.RESERVED_KEYWORDS.contains(entry.getKey())){
					pangoolField.addProp(entry.getKey(),entry.getValue());
				}
			}
			fields.add(pangoolField);
			
		}
		Schema schema = new Schema(avroSchema.getFullName(), fields);
		return schema;
	}
1312661
public Schema createSchema(SAXSource source, PropertyMap properties)
            throws IOException, SAXException, IncorrectSchemaException {
    ErrorHandler eh = properties.get(ValidateProperty.ERROR_HANDLER);
    CountingErrorHandler ceh = new CountingErrorHandler(eh);
    InputSource in = source.getInputSource();
    String systemId = in.getSystemId();
    IfValidHandler ifValidHandler = new IfValidHandler();
    ifValidHandler.setErrorHandler(ceh);
    try {
      SAXTransformerFactory factory = (SAXTransformerFactory)transformerFactoryClass.newInstance();
      initTransformerFactory(factory);
      TransformerHandler transformerHandler = factory.newTransformerHandler(schematron);
      ifValidHandler.setDelegate(transformerHandler);
      Transformer transformer = transformerHandler.getTransformer();
      String phase = properties.get(SchematronProperty.PHASE);
      if (phase != null)
        transformer.setParameter("phase", phase);
      boolean diagnose = properties.contains(SchematronProperty.DIAGNOSE);
      if (diagnose)
        transformer.setParameter("diagnose", Boolean.TRUE);
      PropertyMapBuilder builder = new PropertyMapBuilder(properties);
      builder.put(ValidateProperty.ERROR_HANDLER, ifValidHandler);
      Validator validator = schematronSchema.createValidator(builder.toPropertyMap());
      ifValidHandler.setValidator(validator.getContentHandler());
      XMLReader xr = source.getXMLReader();
      if (xr == null)
        xr = ResolverFactory.createResolver(properties).createXMLReader();
      xr.setContentHandler(ifValidHandler);      
      xr.setDTDHandler(validator.getDTDHandler());  // not strictly necessary
      factory.setErrorListener(new SAXErrorListener(ceh, systemId));
      TemplatesHandler templatesHandler = factory.newTemplatesHandler();
      templatesHandler.setSystemId(systemId);
      LocationFilter stage2 = new LocationFilter(new ErrorFilter(templatesHandler, ceh, localizer), systemId);
      transformerHandler.setResult(new SAXResult(stage2));
      xr.setErrorHandler(ceh);
      xr.parse(in);
      SAXException exception = stage2.getException();
      if (exception != null)
        throw exception;
      if (ceh.getHadErrorOrFatalError())
        throw new IncorrectSchemaException();
      // Getting the templates can cause errors to be generated.
      Templates templates = templatesHandler.getTemplates();
      if (ceh.getHadErrorOrFatalError())
        throw new IncorrectSchemaException();
      return new SchemaImpl(templates,
                            transformerFactoryClass,
                            properties,
                            supportedPropertyIds);
    }
    catch (SAXException e) {
      throw cleanupSAXException(e);
    }
    catch (TransformerConfigurationException e) {
      throw new SAXException(localizer.message("unexpected_schema_creation_error"));
    }
    catch (InstantiationException e) {
      throw new SAXException(e);
    }
    catch (IllegalAccessException e) {
      throw new SAXException(e);
    }
  }
690682
@Override
    /**
     * Export schema handles the handleOperation method.
     */
    public void exportSchema(final String persistenceUnit, List<TableInfo> schemas)
    {
        cql_version = externalProperties != null ? (String) externalProperties.get(CassandraConstants.CQL_VERSION)
                : CassandraConstants.CQL_VERSION_2_0;
        super.exportSchema(persistenceUnit, schemas);
    }
568723
@Override
  public EnvelopeSchemaConverter init(WorkUnitState workUnit) {
    if (workUnit.contains(ConfigurationKeys.EXTRACT_TABLE_NAME_KEY)) {
      String removeFieldsPropName = workUnit.getProp(ConfigurationKeys.EXTRACT_TABLE_NAME_KEY) + AvroProjectionConverter.REMOVE_FIELDS;
      if (workUnit.contains(removeFieldsPropName)) {
        this.fieldRemover = Optional.of(new AvroSchemaFieldRemover(workUnit.getProp(removeFieldsPropName)));
      } else {
        this.fieldRemover = Optional.absent();
      }
    }
    String registryFactoryField = workUnit.contains(KafkaSchemaRegistryFactory.KAFKA_SCHEMA_REGISTRY_FACTORY_CLASS) ?
        workUnit.getProp(KafkaSchemaRegistryFactory.KAFKA_SCHEMA_REGISTRY_FACTORY_CLASS) : DEFAULT_KAFKA_SCHEMA_REGISTRY_FACTORY_CLASS;
    try {
      KafkaSchemaRegistryFactory registryFactory = ((Class<? extends KafkaSchemaRegistryFactory>) Class.forName(registryFactoryField)).newInstance();
      this.registry = registryFactory.create(workUnit.getProperties());
    } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
      return null;
    }
    this.decoderFactory = DecoderFactory.get();
    this.readers = CacheBuilder.newBuilder().build(new CacheLoader<Schema, GenericDatumReader<GenericRecord>>() {
      @Override
      public GenericDatumReader<GenericRecord> load(final Schema key) throws Exception {
        return new GenericDatumReader<>(key);
      }
    });
    return this;
  }
451185
public static org.apache.avro.Schema toAvroSchema(Schema pangoolSchema) {
		List<org.apache.avro.Schema.Field> avroFields = new ArrayList<org.apache.avro.Schema.Field>();

		for(Field pangoolField : pangoolSchema.getFields()) {
			org.apache.avro.Schema.Type avroFieldType = null;
			org.apache.avro.Schema.Field avroField = null;
			org.apache.avro.Schema avroFieldSchema=null;
			switch(pangoolField.getType()){
				case INT: 
				case FLOAT: 
				case DOUBLE: 
				case LONG: 
				case BOOLEAN: 
				case STRING:  
				case BYTES:
					avroFieldType = org.apache.avro.Schema.Type.valueOf(pangoolField.getType().toString());
					avroFieldSchema =org.apache.avro.Schema.create(avroFieldType); 
					avroField = new org.apache.avro.Schema.Field(pangoolField.getName(),avroFieldSchema
							,null,null);
				break;
				case OBJECT: 
					avroFieldType = org.apache.avro.Schema.Type.BYTES; 
					avroFieldSchema = org.apache.avro.Schema.create(avroFieldType);
					avroField = new org.apache.avro.Schema.Field(pangoolField.getName(),avroFieldSchema
							,null,null);
					avroField.addProp(Field.METADATA_BYTES_AS_OBJECT,"true");
					
				break;
				case ENUM: 
					avroFieldType = org.apache.avro.Schema.Type.ENUM;
					Object[] enumValues = pangoolField.getObjectClass().getEnumConstants();
					List<String> values=new ArrayList<String>();
					for (Object e : enumValues){
						values.add(e.toString());
					}
					avroFieldSchema = org.apache.avro.Schema.createEnum(pangoolField.getName(),null,null, values);
					avroField = new org.apache.avro.Schema.Field(pangoolField.getName(),avroFieldSchema
							,null,null);
					break;
				default:
					throw new PangoolRuntimeException("Not avro conversion from Pangool Schema type:" + pangoolField.getType());
				
			}
			if (pangoolField.getObjectClass() != null){
				avroField.addProp(Field.METADATA_OBJECT_CLASS, pangoolField.getObjectClass().getName());
			}
			if (pangoolField.getObjectSerialization() != null){
				avroField.addProp(Field.METADATA_OBJECT_SERIALIZATION,pangoolField.getObjectSerialization().getName());
			}
			for (Map.Entry<String,String> property : pangoolField.getProps().entrySet()){
				avroField.addProp(property.getKey(),property.getValue());
			}
			avroFields.add(avroField);
		}
		org.apache.avro.Schema avroSchema = org.apache.avro.Schema.createRecord(pangoolSchema.getName(), null, null, false);
		avroSchema.setFields(avroFields);
		return avroSchema;
	}
782914
@Override
  public Iterable<GenericRecord> convertRecordImpl(Schema outputSchema, GenericRecord inputRecord, WorkUnitState workUnit)
      throws DataConversionException {
    try {
      return new SingleRecordIterable<>(AvroUtils.convertRecordSchema(inputRecord, outputSchema));
    } catch (IOException e) {
      throw new DataConversionException(e);
    }
  }
191607
protected Object convertFieldValue(Schema outputSchema, Field field, GenericRecord inputRecord,
      WorkUnitState workUnit)
      throws DataConversionException {
    if (field.name().equals(payloadField)) {
      return upConvertPayload(inputRecord);
    }
    return inputRecord.get(field.name());
  }
97011
public static void writeSchema(String outputPath, Schema schema, JavaSparkContext sc) throws IOException {
        writeStringToFile(outputPath, schema.toString(), sc);
    }
211244
public static Schema decorateRecordSchema(Schema inputSchema, @Nonnull List<Field> fieldList) {
    Preconditions.checkState(inputSchema.getType().equals(Type.RECORD));
    List<Field> outputFields = deepCopySchemaFields(inputSchema);
    List<Field> newOutputFields = Stream.concat(outputFields.stream(), fieldList.stream()).collect(Collectors.toList());

    Schema outputSchema = Schema.createRecord(inputSchema.getName(), inputSchema.getDoc(),
            inputSchema.getNamespace(), inputSchema.isError());
    outputSchema.setFields(newOutputFields);
    copyProperties(inputSchema, outputSchema);
    return outputSchema;
  }
610538
def convert(schema):
    """"""
    # pylint: disable=too-many-return-statements,too-many-branches
    if isinstance(schema, vol.Schema):
        schema = schema.schema

    if isinstance(schema, Mapping):
        val = []

        for key, value in schema.items():
            description = None
            if isinstance(key, vol.Marker):
                pkey = key.schema
                description = key.description
            else:
                pkey = key

            pval = convert(value)
            pval['name'] = pkey
            if description is not None:
                pval['description'] = description

            if isinstance(key, (vol.Required, vol.Optional)):
                pval[key.__class__.__name__.lower()] = True

                if key.default is not vol.UNDEFINED:
                    pval['default'] = key.default()

            val.append(pval)

        return val

    if isinstance(schema, vol.All):
        val = {}
        for validator in schema.validators:
            val.update(convert(validator))
        return val

    if isinstance(schema, (vol.Clamp, vol.Range)):
        val = {}
        if schema.min is not None:
            val['valueMin'] = schema.min
        if schema.max is not None:
            val['valueMax'] = schema.max
        return val

    if isinstance(schema, vol.Length):
        val = {}
        if schema.min is not None:
            val['lengthMin'] = schema.min
        if schema.max is not None:
            val['lengthMax'] = schema.max
        return val

    if isinstance(schema, vol.Datetime):
        return {
            'type': 'datetime',
            'format': schema.format,
        }

    if isinstance(schema, vol.In):
        if isinstance(schema.container, Mapping):
            return {
                'type': 'select',
                'options': list(schema.container.items()),
            }
        return {
            'type': 'select',
            'options': [(item, item) for item in schema.container]
        }

    if schema in (vol.Lower, vol.Upper, vol.Capitalize, vol.Title, vol.Strip):
        return {
            schema.__name__.lower(): True,
        }

    if isinstance(schema, vol.Coerce):
        schema = schema.type

    if schema in TYPES_MAP:
        return {'type': TYPES_MAP[schema]}

    raise ValueError('Unable to convert schema: {}'.format(schema))
776397
private static void generateSchema(SQLiteDatabaseSchema schema) throws FileNotFoundException, IOException {
		// when we run in JUNIT of Kripton, we don't have to generate schemas
		// if (BindDataSourceSubProcessor.JUNIT_TEST_MODE)
		// return;
		if (!schema.generateSchema)
			return;

		// and now, write schema.create.v and schema.drop.v
		String schemaCreation = defineFileName(schema);

		String schemaLocation = KriptonOptions.getSchemaLocation();

		File schemaCreatePath = new File(schemaLocation).getAbsoluteFile();
		File schemaCreateFile = new File(schemaLocation, schemaCreation).getAbsoluteFile();
		schemaCreatePath.mkdirs();

		AnnotationProcessorUtilis.infoOnGeneratedFile(BindDataSource.class, schemaCreateFile);
		FileOutputStream fos = new FileOutputStream(schemaCreateFile);
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));

		bw.write("------------------------------------------------------------------------------------\n");
		bw.write("--\n");
		bw.write("-- Filename: " + schemaCreation + "\n");
		bw.write("--\n");
		bw.write(String.format("-- Date: %s", (new Date()).toString()) + "\n");
		bw.write("--\n");
		if (!BindDataSourceSubProcessor.JUNIT_TEST_MODE) {
			bw.write(String.format("-- This file was generated by Kripton Annotation Processor v. %s\n",
					Version.getVersion()));
			bw.write(String.format("--\n"));
		}
		bw.write("------------------------------------------------------------------------------------\n");
		bw.newLine();
		for (String sql : schema.sqlForCreate) {
			bw.write(sql);
			bw.newLine();
		}
		bw.close();
	}
525666
public Schema schema(TableSchema schema) {
		tableSchema.clear();
		lastField = null;
		for (int i = 0; i < schema.getFieldCount(); i++) {
			field(schema.getFieldName(i).get(), schema.getFieldType(i).get());
		}
		return this;
	}
1181033
public void setSchema(String schema) throws SQLException {
        Transaction suspendTx = null;

        if (mcf.beforeJDBCVersion(JDBCRuntimeVersion.VERSION_4_1))
            throw new SQLFeatureNotSupportedException();

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
            Tr.debug(this, tc, "Set Schema to " + schema);
        // Global trans must be suspended for jdbc-4.1 getters and setters on zOS 
        if (AdapterUtil.isZOS() && isGlobalTransactionActive())
            suspendTx = suspendGlobalTran();

        try {
            mcf.jdbcRuntime.doSetSchema(sqlConn, schema);
            currentSchema = schema;
            connectionPropertyChanged = true;
        } catch (SQLException sqle) {
            throw sqle;
        } finally {
            if (suspendTx != null)
                resumeGlobalTran(suspendTx);
        }
    }
906692
public Schema compileSchema( InputStream stream, String systemId )
		throws VerifierConfigurationException, SAXException, IOException {
		
		InputSource is = new InputSource(stream);
		is.setSystemId(systemId);
		return compileSchema(is);
	}
1366977
protected void setSchema(final String schema) throws DatabaseEngineException {
        try {
            this.conn.setSchema(schema);
        } catch (final Exception e) {
            throw new DatabaseEngineException(String.format("Could not set current schema to '%s'", schema), e);
        }
    }
8576
public void setSchema(String schema)
   {
      if (schema == null)
      {
         schema = "";
      }
      else
      {
         if (!schema.isEmpty() && !schema.endsWith("."))
         {
            schema = schema + '.';
         }
      }
      m_schema = schema;
   }