import groovy.json.JsonOutput import groovy.json.JsonSlurper import groovy.json.JsonBuilder import java.nio.charset.StandardCharsets import java.time.Instant import java.time.ZoneOffset def resJson = "to_arrays\\n convert_types)]\\n File \\\"/usr/local/lib/python3.7/site-packages/pyarrow/pandas_compat.py\\\", line 467, in <listcomp>\\n for c, t in zip(columns_to_convert,\\n File \\\"/usr/local/lib/python3.7/site-packages/pyarrow/pandas_compat.py\\\", line 463, in convert_column\\n raise e\\n File \\\"/usr/local/lib/python3.7/site-packages/pyarrow/pandas_compat.py\\\", line 457, in convert_column\\n return pa.array(col, type=ty, from_pandas=True, safe=safe)\\n File \\\"pyarrow/array.pxi\\\", line 169, in pyarrow.lib.array\\n File \\\"pyarrow/array.pxi\\\", line 78, in pyarrow.lib._ndarray_to_array\\n File \\\"pyarrow/error.pxi\\\", line 91, in pyarrow.lib.check_status\\npyarrow.lib.ArrowTypeError: (\\\"Expected a bytes object, got a 'datetime.datetime' object\\\", 'Conversion failed for column Unnamed: 8 with type object')\"}\n{\"asctime\": \"2020-05-15 14:05:59,753\", \"message\": \"Exception occurred during Parquet conversion.\", \"exc_info\": \"Traceback (most recent call last):\\n File \\\"./ExcelToParquetConverter.py\\\", line 67, in conversion_process\\n parq_file_name = convert_df_to_parquet(df, file_path, sheetname)\\n File \\\"./ExcelToParquetConverter.py\\\", line 36, in convert_df_to_parquet\\n df.to_parquet(os.path.join(output_file_location,parq_file_name), engine='pyarrow',index=False, compression=None)\\n File \\\"/usr/local/lib/python3.7/site-packages/pandas/core/frame.py\\\", line 2237, in to_parquet\\n **kwargs\\n File \\\"/usr/local/lib/python3.7/site-packages/pandas/io/parquet.py\\\", line 254, in to_parquet\\n **kwargs\\n File \\\"/usr/local/lib/python3.7/site-packages/pandas/io/parquet.py\\\", line 101, in write\\n table = self.api.Table.from_pandas(df, **from_pandas_kwargs)\\n File \\\"pyarrow/table.pxi\\\", line 1139, in pyarrow.lib.Table.from_pandas\\n File \\\"/usr/local/lib/python3.7/site-packages/pyarrow/pandas_compat.py\\\", line 468, in dataframe_to_arrays\\n convert_types)]\\n File \\\"/usr/local/lib/python3.7/site-packages/pyarrow/pandas_compat.py\\\", line 467, in <listcomp>\\n for c, t in zip(columns_to_convert,\\n File \\\"/usr/local/lib/python3.7/site-packages/pyarrow/pandas_compat.py\\\", line 463, in convert_column\\n raise e\\n File \\\"/usr/local/lib/python3.7/site-packages/pyarrow/pandas_compat.py\\\", line 457, in convert_column\\n return pa.array(col, type=ty, from_pandas=True, safe=safe)\\n File \\\"pyarrow/array.pxi\\\", line 169, in pyarrow.lib.array\\n File \\\"pyarrow/array.pxi\\\", line 78, in pyarrow.lib._ndarray_to_array\\n File \\\"pyarrow/error.pxi\\\", line 91, in pyarrow.lib.check_status\\npyarrow.lib.ArrowTypeError: (\\\"Expected a bytes object, got a 'datetime.datetime' object\\\", 'Conversion failed for column Nick with type object')\"}\n{\"asctime\": \"2020-05-15 14:05:59,760\", \"message\": \"Exception occurred during Parquet conversion.\", \"exc_info\": \"Traceback (most recent call last):\\n File \\\"./ExcelToParquetConverter.py\\\", line 67, in conversion_process\\n parq_file_name = convert_df_to_parquet(df, file_path, sheetname)\\n File \\\"./ExcelToParquetConverter.py\\\", line 36, in convert_df_to_parquet\\n df.to_parquet(os.path.join(output_file_location,parq_file_name), engine='pyarrow',index=False, compression=None)\\n File \\\"/usr/local/lib/python3.7/site-packages/pandas/core/frame.py\\\", line 2237, in to_parquet\\n **kwargs\\n File \\\"/usr/local/lib/python3.7/site-packages/pandas/io/parquet.py\\\", line 254, in to_parquet\\n **kwargs\\n File \\\"/usr/local/lib/python3.7/site-packages/pandas/io/parquet.py\\\", line 94, in write\\n self.validate_dataframe(df)\\n File \\\"/usr/local/lib/python3.7/site-packages/pandas/io/parquet.py\\\", line 59, in validate_dataframe\\n raise ValueError(\\\"parquet must have string column names\\\")\\nValueError: parquet must have string column names\"}\n{\"asctime\": \"2020-05-15 14:05:59,763\", \"message\": \"SUCCESS\", \"record_type\": \"output\", \"response\": [{\"file_path\": \"c4ac1618-7090-42a4-ace3-1ea632960dc1-m93vof528og2f04/sandboxes.xlsx\", \"file_size_MB\": 0.5509061813354492, \"number_of_sheets\": 15, \"excel_read_time\": \"0:00:01.288161\", \"sheet_stats\": [{\"sheet_name\": \"E2E - Automated (Heye)\", \"row_num\": 33, \"col_num\": 29, \"df_memory_usage_MB\": 0.033463478088378906, \"conversion_exception\": \"(\\\"Expected a bytes object, got a 'datetime.datetime' object\\\", 'Conversion failed for column Unnamed: 4 with type object')\", \"parq_conversion_time\": \"0:00:00.249592\"}, {\"sheet_name\": \"E2E Testi(Heye) \", \"row_num\": 50, \"col_num\": 25, \"df_memory_usage_MB\": 0.02248382568359375, \"converted_filename\": \"sandboxes_xlsx_E2E_Testi_Heye_.parquet\", \"parq_conversion_time\": \"0:00:00.142385\"}, {\"sheet_name\": \"Sandboxes\", \"row_num\": 110, \"col_num\": 5, \"df_memory_usage_MB\": 0.02681255340576172, \"conversion_exception\": \"(\\\"Expected a bytes object, got a 'int' object\\\", 'Conversion failed for column Unnamed: 2 with type object')\", \"parq_conversion_time\": \"0:00:00.001799\"}, {\"sheet_name\": \"Data Validation Options\", \"row_num\": 47, \"col_num\": 10, \"df_memory_usage_MB\": 0.016343116760253906, \"converted_filename\": \"sandboxes_xlsx_Data_Validation_Options.parquet\", \"parq_conversion_time\": \"0:00:00.108872\"}, {\"sheet_name\": \"Template Test Run Log\", \"row_num\": 124, \"col_num\": 34, \"df_memory_usage_MB\": 0.1176614761352539, \"conversion_exception\": \"(\\\"Expected a bytes object, got a 'datetime.datetime' object\\\", 'Conversion failed for column Unnamed: 8 with type object')\", \"parq_conversion_time\": \"0:00:00.001892\"}, {\"sheet_name\": \"E2E Testing - UAT (Heye) \", \"row_num\": 39, \"col_num\": 9, \"df_memory_usage_MB\": 0.013439178466796875, \"conversion_exception\": \"(\\\"Expected a bytes object, got a 'int' object\\\", 'Conversion failed for column Unnamed: 0 with type object')\", \"parq_conversion_time\": \"0:00:00.001582\"}, {\"sheet_name\": \"Bugs (Grant)\", \"row_num\": 2, \"col_num\": 3, \"df_memory_usage_MB\": 0.000438690185546875, \"converted_filename\": \"sandboxes_xlsx_Bugs_Grant_.parquet\", \"parq_conversion_time\": \"0:00:00.115669\"}, {\"sheet_name\": \"Content - Big 4 ERP & Generic (\", \"row_num\": 1000, \"col_num\": 10, \"df_memory_usage_MB\": 0.2853097915649414, \"converted_filename\": \"sandboxes_xlsx_Content_Big_4_ERP_Generic_.parquet\", \"parq_conversion_time\": \"0:00:00.112185\"}, {\"sheet_name\": \"Content - CATs (Thompson)\", \"row_num\": 12, \"col_num\": 9, \"df_memory_usage_MB\": 0.005036354064941406, \"conversion_exception\": \"(\\\"Expected a bytes object, got a 'datetime.datetime' object\\\", 'Conversion failed for column Unnamed: 3 with type object')\", \"parq_conversion_time\": \"0:00:00.002138\"}, {\"sheet_name\": \"Content - PS Loader (Kidd)\", \"row_num\": 1002, \"col_num\": 34, \"df_memory_usage_MB\": 0.6301660537719727, \"converted_filename\": \"sandboxes_xlsx_Content_PS_Loader_Kidd_.parquet\", \"parq_conversion_time\": \"0:00:00.155707\"}, {\"sheet_name\": \"Qlik-CSV Load and Performance (\", \"row_num\": 903, \"col_num\": 17, \"df_memory_usage_MB\": 0.26372814178466797, \"conversion_exception\": \"(\\\"Expected a bytes object, got a 'int' object\\\", 'Conversion failed for column Time per Dataset with type object')\", \"parq_conversion_time\": \"0:00:00.001769\"}, {\"sheet_name\": \"Qlik - CSV process & app (Johns\", \"row_num\": 899, \"col_num\": 22, \"df_memory_usage_MB\": 0.5512275695800781, \"conversion_exception\": \"(\\\"Expected a bytes object, got a 'datetime.datetime' object\\\", 'Conversion failed for column Unnamed: 8 with type object')\", \"parq_conversion_time\": \"0:00:00.002187\"}, {\"sheet_name\": \"Content - Mid Tier (Kidd)\", \"row_num\": 981, \"col_num\": 31, \"df_memory_usage_MB\": 0.5049076080322266, \"converted_filename\": \"sandboxes_xlsx_Content_Mid_Tier_Kidd_.parquet\", \"parq_conversion_time\": \"0:00:00.123954\"}, {\"sheet_name\": \"NickMark\", \"row_num\": 1000, \"col_num\": 4, \"df_memory_usage_MB\": 0.1251058578491211, \"conversion_exception\": \"(\\\"Expected a bytes object, got a 'datetime.datetime' object\\\", 'Conversion failed for column Nick with type object')\", \"parq_conversion_time\": \"0:00:00.002446\"}, {\"sheet_name\": \"QA - QlikView Evidence Screensh\", \"row_num\": 37, \"col_num\": 27, \"df_memory_usage_MB\": 0.02728271484375, \"conversion_exception\": \"parquet must have string column names\", \"parq_conversion_time\": \"0:00:00.001505\"}]}]}\n/usr/local/lib/python3.7/site-packages/openpyxl/worksheet/_reader.py:295: UserWarning: Data Validation extension is not supported and will be removed\n warn(msg)\n" // inputJson = slurper.parseText(inputString) // containerName = 'c4ac1618-7090-42a4-ace3-1ea632960dc1-m93vof528og2f04' // if (Objects.nonNull(inputJson)) { // def resJson = inputJson[containerName + '-logs'] if (Objects.nonNull(resJson)) { if (resJson.toString().contains(errMsg)) { resJson = resJson.toString().replaceAll(errMsg , '') } } excelParquetConversionResultDetails = slurper.parseText(resJson) } excelParquetConversionResult = excelParquetConversionResultDetails.message as String payload = [ "excelParquetConversion": excelParquetConversionResult ] println(JsonOutput.toJson(payload))
Write, Run & Share Groovy code online using OneCompiler's Groovy online compiler for free. It's one of the robust, feature-rich online compilers for Groovy language, running the latest Groovy version 2.6. Getting started with the OneCompiler's Groovy editor is easy and fast. The editor shows sample boilerplate code when you choose language as Groovy and start coding.
OneCompiler's Groovy online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample Groovy program which takes name as input and prints hello message with your name.
def name = System.in.newReader().readLine()
println "Hello " + name
Groovy is an object-oriented programming language based on java. Apache Groovy is a dynamic and agile language which is similar to Python, Ruby, Smalltalk etc.
Data type | Description | Range |
---|---|---|
String | To represent text literals | NA |
char | To represent single character literal | NA |
int | To represent whole numbers | -2,147,483,648 to 2,147,483,647 |
short | To represent short numbers | -32,768 to 32,767 |
long | To represent long numbers | -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807 |
double | To represent 64 bit floating point numbers | 4.94065645841246544e-324d to 1.79769313486231570e+308d |
float | To represent 32 bit floating point numbers | 1.40129846432481707e-45 to 3.40282346638528860e+38 |
byte | To represent byte value | -128 to 127 |
boolean | To represent boolean values either true or false | True or False |
You can define variables in two ways
data-type variable-name;
[or]
def variable-name;
0.upto(n) {println "$it"}
or
n.times{println "$it"}
where n is the number of loops and 0 specifies the starting index
When ever you want to perform a set of operations based on a condition or set of conditions, then If / Nested-If / If-Else is used.
if(conditional-expression) {
// code
} else {
// code
}
Switch is an alternative to If-Else-If ladder and to select one among many blocks of code.
switch(conditional-expression) {
case value1:
// code
break; // optional
case value2:
// code
break; // optional
...
default:
//code to be executed when all the above cases are not matched;
}
List allows you to store ordered collection of data values.
def mylist = [1,2,3,4,5];
List Methods | Description |
---|---|
size() | To find size of elements |
sort() | To sort the elements |
add() | To append new value at the end |
contains() | Returns true if this List contains requested value. |
get() | Returns the element of the list at the definite position |
pop() | To remove the last item from the List |
isEmpty() | Returns true if List contains no elements |
minus() | This allows you to exclude few specified elements from the elements of the original |
plus() | This allows you to add few specified elements to the elements of the original |
remove() | To remove the element present at the specific position |
reverse() | To reverse the elements of the original List and creates new list |