[
https://issues.apache.org/jira/browse/FREEMARKER-144?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17120631#comment-17120631
]
Siegfried Goeschl commented on FREEMARKER-144:
----------------------------------------------
Got a POC working
{noformat}
<#ftl output_format="plainText">
<#--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you 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.
-->
<#assign cvsFormat = CSVTool.formats["DEFAULT"].withHeader().withDelimiter(';')>
<#assign csvParser = CSVTool.parse(DataSources.get(0), cvsFormat)>
<#assign users = DataFrameTool.toDataFrame(csvParser)>
Original Data
=============================================================================
${DataFrameTool.print(users)}
Select & Sort Users
=============================================================================
users.
.select("(name == 'Schmitt' || name == 'Meier') && country == 'Germany'")
.sort("name", DataFrameTool.sortOrder["ASCENDING"])
${DataFrameTool.print(users
.select("(name == 'Schmitt' || name == 'Meier') && country == 'Germany'")
.sort("name", DataFrameTool.sortOrder["ASCENDING"]))}
Head of Users
=============================================================================
users.head(2)
${DataFrameTool.print(users.head(2))}
Remove Column From Users
=============================================================================
users.removeColumn("age"))
${DataFrameTool.print(users.removeColumn("age"))}
{noformat}
{noformat}
Original Data
=============================================================================
┌────────────┬────────────┬────────────┐
│#name │#age │#country │
├────────────┼────────────┼────────────┤
│Schmitt │24 │Germany │
├────────────┼────────────┼────────────┤
│Parker │45 │USA │
├────────────┼────────────┼────────────┤
│Meier │20 │Germany │
├────────────┼────────────┼────────────┤
│Schmitt │30 │France │
├────────────┼────────────┼────────────┤
│Peter │44 │Germany │
├────────────┼────────────┼────────────┤
│Meier │24 │Germany │
├────────────┼────────────┼────────────┤
│Green │33 │UK │
├────────────┼────────────┼────────────┤
│Schmitt │30 │Germany │
├────────────┼────────────┼────────────┤
│Meier │30 │Germany │
└────────────┴────────────┴────────────┘
Select & Sort Users
=============================================================================
users.
.select("(name == 'Schmitt' || name == 'Meier') && country == 'Germany'")
.sort("name", DataFrameTool.sortOrder["ASCENDING"])
┌────────────┬────────────┬────────────┐
│#name │#age │#country │
├────────────┼────────────┼────────────┤
│Meier │20 │Germany │
├────────────┼────────────┼────────────┤
│Meier │24 │Germany │
├────────────┼────────────┼────────────┤
│Meier │30 │Germany │
├────────────┼────────────┼────────────┤
│Schmitt │24 │Germany │
├────────────┼────────────┼────────────┤
│Schmitt │30 │Germany │
└────────────┴────────────┴────────────┘
Head of Users
=============================================================================
users.head(2)
┌────────────┬────────────┬────────────┐
│#name │#age │#country │
├────────────┼────────────┼────────────┤
│Schmitt │24 │Germany │
├────────────┼────────────┼────────────┤
│Parker │45 │USA │
└────────────┴────────────┴────────────┘
Remove Column From Users
=============================================================================
users.removeColumn("age"))
┌────────────┬────────────┐
│#name │#country │
├────────────┼────────────┤
│Schmitt │Germany │
├────────────┼────────────┤
│Parker │USA │
├────────────┼────────────┤
│Meier │Germany │
├────────────┼────────────┤
│Schmitt │France │
├────────────┼────────────┤
│Peter │Germany │
├────────────┼────────────┤
│Meier │Germany │
├────────────┼────────────┤
│Green │UK │
├────────────┼────────────┤
│Schmitt │Germany │
├────────────┼────────────┤
│Meier │Germany │
└────────────┴────────────┘
{noformat}
> [freemarker-cli] Proof Of Concept for providing DataFrames
> ----------------------------------------------------------
>
> Key: FREEMARKER-144
> URL: https://issues.apache.org/jira/browse/FREEMARKER-144
> Project: Apache Freemarker
> Issue Type: Task
> Reporter: Siegfried Goeschl
> Assignee: Siegfried Goeschl
> Priority: Major
>
> Sometime users need to massage tabular data coming from CSV or an Excel
> sheet, eg.. joining on columns
> * There is some ad-hoc code in the FreeMarker Generator CSV tool
> * I had a look at available DataFrame libraries (see
> https://medium.com/@thijser/doing-cool-data-science-in-java-how-3-dataframe-libraries-stack-up-5e6ccb7b437)
> I finally found [nRo/DataFrame|https://github.com/nRo/DataFrame] and it would
> make a good fit
> * Comes with MIT licence
> * Depends only on `antlr4-runtime` and `slf4j`
> * It's API would fit nicely into a FreeMarker Template
> * It provides a DataFrame implementation and some basic transformations
> * It currently does not support temporal column types
> What I would like to implement is
> * Reading CSV & Excel into a DataFrame
> * Write a DataFrame to CSV
--
This message was sent by Atlassian Jira
(v8.3.4#803005)