001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.marshall.parquet;
018
019import static java.lang.annotation.ElementType.*;
020import static java.lang.annotation.RetentionPolicy.*;
021import static org.apache.juneau.commons.utils.Shorts.*;
022
023import java.lang.annotation.*;
024
025import org.apache.juneau.commons.reflect.*;
026import org.apache.juneau.commons.svl.*;
027import org.apache.juneau.marshall.*;
028
029/**
030 * Utility classes for the {@link ParquetConfig @ParquetConfig} annotation.
031 */
032public class ParquetConfigAnnotation {
033
034   private ParquetConfigAnnotation() {}
035
036   /**
037    * Applies {@link ParquetConfig} annotations to a {@link ParquetSerializer.Builder}.
038    */
039   public static class SerializerApply extends AnnotationApplier<ParquetConfig,ParquetSerializer.Builder> {
040
041      /**
042       * Constructor.
043       *
044       * @param vr The resolver for resolving values in annotations.
045       *    <br>Must not be <jk>null</jk>.
046       */
047      public SerializerApply(VarResolverSession vr) {
048         super(ParquetConfig.class, ParquetSerializer.Builder.class, vr);
049      }
050
051      @Override
052      public void apply(AnnotationInfo<ParquetConfig> ai, ParquetSerializer.Builder b) {
053         var a = ai.inner();
054         if (!a.compressionCodec().isEmpty())
055            b.compressionCodec(CompressionCodec.forWrite(a.compressionCodec()));
056         if (!a.rowGroupSize().isEmpty())
057            b.rowGroupSize(Integer.parseInt(a.rowGroupSize()));
058         if (!a.pageSize().isEmpty())
059            b.pageSize(Integer.parseInt(a.pageSize()));
060         if (eqic("true", a.addBeanTypes()))
061            b.addBeanTypesParquet(true);
062      }
063   }
064
065   /**
066    * Applies {@link ParquetConfig} annotations to a {@link ParquetParser.Builder}.
067    */
068   public static class ParserApply extends AnnotationApplier<ParquetConfig,ParquetParser.Builder> {
069
070      /**
071       * Constructor.
072       *
073       * @param vr The resolver for resolving values in annotations.
074       *    <br>Must not be <jk>null</jk>.
075       */
076      public ParserApply(VarResolverSession vr) {
077         super(ParquetConfig.class, ParquetParser.Builder.class, vr);
078      }
079
080      @Override
081      public void apply(AnnotationInfo<ParquetConfig> ai, ParquetParser.Builder b) {
082         var a = ai.inner();
083         integer(a.maxLength(), "maxLength").ifPresent(b::maxLength);
084         integer(a.maxCount(), "maxCount").ifPresent(b::maxCount);
085         integer(a.maxInputLength(), "maxInputLength").ifPresent(b::maxInputLength);
086         integer(a.maxDecompressedBytes(), "maxDecompressedBytes").ifPresent(b::maxDecompressedBytes);
087      }
088   }
089
090   /**
091    * A collection of {@link ParquetConfig @ParquetConfig} annotations.
092    */
093   @Documented
094   @Target({ METHOD, TYPE })
095   @Retention(RUNTIME)
096   @Inherited
097   public static @interface Array {
098      /** The child annotations. */
099      ParquetConfig[] value();
100   }
101}