esProc SPLDouble The Development Efficiency of Java Programmers

The Dilemma of Java Programmers

Data processing: Java or SQL?

Let’s See How Complicated Java Can Get

e.g.Group by two fields and aggregate

In Java

Map < Integer, Map < String, Double > > summary = new HashMap<>();
for (Order order : orders) {
	int year = order.orderDate.getYear();
	String sellerId = order.sellerId;
	double amount = order.amount;
	Map < String, Double> salesMap = summary.get(year);
	if (salesMap == null) {
		salesMap = new HashMap<>();
		summary.put(year, salesMap);
	}
	Double totalAmount = salesMap.get(sellerId);
	if (totalAmount == null) {
		totalAmount = 0.0;
	}
	salesMap.put(sellerId, totalAmount + amount);
}
for (Map.Entry < Integer, Map < String, Double > > entry : summary.entrySet()) {
	int year = entry.getKey();
	Map < String, Double> salesMap = entry.getValue();
	System.out.println("Year: " + year);
	for (Map.Entry < String, Double> salesEntry : salesMap.entrySet()) {
		String sellerId = salesEntry.getKey();
		double totalAmount = salesEntry.getValue();
		System.out.println("  Seller ID: " + sellerId + ", Total Amount: " + totalAmount);
	}
}

Just one line in SQL

SELECT year(orderdate),sellerid,sum(amount) FROM orders  GROUP BY year(orderDate),sellerid
Stream, Kotlin, and Scala improve just a little

Stream

 Map < Integer, Map < String, Double > > summary = orders.stream()
		.collect(Collectors.groupingBy(
				order -> order.orderDate.getYear(),
				Collectors.groupingBy(
						order -> order.sellerId,
						Collectors.summingDouble(order -> order.amount)
				)
		));

summary.forEach((year, salesMap) -> {
	System.out.println("Year: " + year);
	salesMap.forEach((sellerId, totalAmount) -> {
		System.out.println("  Seller ID: " + sellerId + ", Total Amount: " + totalAmount);
	});
});

Kotlin

val summary = orders
	.groupBy { it.orderDate.year }
	.mapValues { yearGroup ->
		yearGroup.value
			.groupBy { it.sellerId }
			.mapValues { sellerGroup ->
				sellerGroup.value.sumOf { it.amount }
			}
	}
summary.forEach { (year, salesMap) ->
	println("Year: $year")
	salesMap.forEach { (sellerId, totalAmount) ->
		println("  Seller ID: $sellerId, Total Amount: $totalAmount")
	}
}

Scala

val summary = orders
	.groupBy(order => order.orderDate.getYear)
	.mapValues(yearGroup =>
		yearGroup
			.groupBy(_.sellerId)
			.mapValues(sellerGroup => sellerGroup.map(_.amount).sum)
)

summary.foreach { case (year, salesMap) =>
	println(s"Year: $year")
	salesMap.foreach { case (sellerId, totalAmount) =>
		println(s"  Seller ID: $sellerId, Total Amount: $totalAmount")
	}
}

Compiled Languages Do Not Support Hot-Swapping

Difficult to adapt to rapidly changing business requirements.

esProc SPL Frees Java Programmers from The Dilemma!

The code is simpler than Java, as concise as SQL.

e.g.Group by two fields and aggregate
SPLOrders.groups(year(orderdate),sellerid;sum(amount))
SQLSELECT year(orderdate),sellerid,sum(amount) FROM orders GROUP BY year(orderDate),sellerid
Actually, it’s even simpler than SQL.
e.g.Calculate the consecutive rising days of the stock

SQL

SELECT MAX(ContinuousDays)
FROM (SELECT COUNT(*) ContinuousDays
	FROM (SELECT SUM(UpDownTag) OVER ( ORDER BY TradeDate) NoRisingDays
		FROM (SELECT TradeDate,
					CASE WHEN price>LAG(price) OVER ( ORDER BY TradeDate)
						THEN 0 ELSE 1 END UpDownTag
				FROM Stock ) )
	GROUP BY NoRisingDays )

SPL

A
1=Stock.sort(tradeDate).group@i(price < price[-1]).max(~.len())

Pure Java Development, Seamless Integrated into Java Frameworks.
Enjoying architectural benefits without any dilemma.

Embedding JARs for usage

Class.forName("com.esproc.jdbc.InternalDriver");
con= DriverManager.getConnection("jdbc:esproc:local://");
st =con.prepareCall("call SplScript(?)");
st.setObject(1, "A");
st.execute();
ResultSet rs = st.getResultSet();
ResultSetMetaData rsmd = rs.getMetaData();

Use standard JDBC to execute and call SPL scripts

Collaborate with Java frameworks

Interpreted Language SPL, Built-in Hot Swapping Support

Rich Data Sources Support.
No dependency on databases—works without a database, or with multiple databases.