|
| 1 | +package io.odpf.dagger.functions.udfs.python; |
| 2 | + |
| 3 | +import com.google.gson.Gson; |
| 4 | +import com.google.gson.GsonBuilder; |
| 5 | +import com.google.gson.annotations.SerializedName; |
| 6 | +import io.odpf.dagger.common.configuration.Configuration; |
| 7 | +import lombok.Getter; |
| 8 | + |
| 9 | +import static io.odpf.dagger.functions.common.Constants.*; |
| 10 | + |
| 11 | +/** |
| 12 | + * The type Python udf config. |
| 13 | + */ |
| 14 | +public class PythonUdfConfig { |
| 15 | + private static final Gson GSON = new GsonBuilder() |
| 16 | + .enableComplexMapKeySerialization() |
| 17 | + .setPrettyPrinting() |
| 18 | + .create(); |
| 19 | + |
| 20 | + @SerializedName(PYTHON_FILES_KEY) |
| 21 | + private String pythonFiles; |
| 22 | + |
| 23 | + @SerializedName(PYTHON_REQUIREMENTS_KEY) |
| 24 | + @Getter |
| 25 | + private String pythonRequirements; |
| 26 | + |
| 27 | + @SerializedName(PYTHON_ARCHIVES_KEY) |
| 28 | + private String pythonArchives; |
| 29 | + |
| 30 | + @SerializedName(PYTHON_FN_EXECUTION_ARROW_BATCH_SIZE_KEY) |
| 31 | + private Integer pythonArrowBatchSize; |
| 32 | + |
| 33 | + @SerializedName(PYTHON_FN_EXECUTION_BUNDLE_SIZE_KEY) |
| 34 | + private Integer pythonBundleSize; |
| 35 | + |
| 36 | + @SerializedName(PYTHON_FN_EXECUTION_BUNDLE_TIME_KEY) |
| 37 | + private Long pythonBundleTime; |
| 38 | + |
| 39 | + /** |
| 40 | + * Gets python files. |
| 41 | + * |
| 42 | + * @return the python files |
| 43 | + */ |
| 44 | + public String getPythonFiles() { |
| 45 | + if (pythonFiles != null) { |
| 46 | + return pythonFiles.replaceAll("\\s+", ""); |
| 47 | + } |
| 48 | + return null; |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * Gets python archives. |
| 53 | + * |
| 54 | + * @return the python archives |
| 55 | + */ |
| 56 | + public String getPythonArchives() { |
| 57 | + if (pythonArchives != null) { |
| 58 | + return pythonArchives.replaceAll("\\s+", ""); |
| 59 | + } |
| 60 | + return null; |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * Gets python arrow batch size. |
| 65 | + * |
| 66 | + * @return the python arrow batch size |
| 67 | + */ |
| 68 | + public int getPythonArrowBatchSize() { |
| 69 | + if (pythonArrowBatchSize == null) { |
| 70 | + return PYTHON_FN_EXECUTION_ARROW_BATCH_SIZE_DEFAULT; |
| 71 | + } |
| 72 | + return pythonArrowBatchSize; |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * Gets python bundle size. |
| 77 | + * |
| 78 | + * @return the python bundle size |
| 79 | + */ |
| 80 | + public int getPythonBundleSize() { |
| 81 | + if (pythonBundleSize == null) { |
| 82 | + return PYTHON_FN_EXECUTION_BUNDLE_SIZE_DEFAULT; |
| 83 | + } |
| 84 | + return pythonBundleSize; |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * Gets python bundle time. |
| 89 | + * |
| 90 | + * @return the python bundle time |
| 91 | + */ |
| 92 | + public long getPythonBundleTime() { |
| 93 | + if (pythonBundleTime == null) { |
| 94 | + return PYTHON_FN_EXECUTION_BUNDLE_TIME_DEFAULT; |
| 95 | + } |
| 96 | + return pythonBundleTime; |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * Parse python udf config. |
| 101 | + * |
| 102 | + * @param configuration the configuration |
| 103 | + * @return the python udf config |
| 104 | + */ |
| 105 | + public static PythonUdfConfig parse(Configuration configuration) { |
| 106 | + String jsonString = configuration.getString(PYTHON_UDF_CONFIG, ""); |
| 107 | + |
| 108 | + return GSON.fromJson(jsonString, PythonUdfConfig.class); |
| 109 | + } |
| 110 | +} |
0 commit comments