Hi…
We want to add Apache Spark to the JMIX Project. But unable to initiate the Apache Spark Session. I have attached the Sample Project here for your perusal
apache-spark-example.zip (118.3 KB)
.
@EventListener
public void onApplicationStarted(final ApplicationStartedEvent event) {
SparkSession spark = SparkSession.builder()
.appName("SparkFilterExample")
.master("local[2]") // Use local mode with 2 cores for testing
.getOrCreate();
// Read the CSV file into a DataFrame
Dataset<Row> df = spark.read().csv("file.csv")
.toDF("id", "value1", "value2"); // Assign column names
// Apply a filter to select rows where "value1" is greater than 15
Dataset<Row> filteredDF = df.filter("value1 > 15");
// Show the filtered DataFrame
filteredDF.show();
spark.stop();
}
And the build.gradle is below.
plugins {
id 'io.jmix' version '2.1.1'
id 'java'
}
apply plugin: 'org.springframework.boot'
apply plugin: 'com.vaadin'
jmix {
bomVersion = '2.1.1'
projectId = 'spark'
}
group = 'com.company'
version = '0.0.1-SNAPSHOT'
repositories {
mavenCentral()
maven {
url 'https://global.repo.jmix.io/repository/public'
}
}
dependencies {
implementation 'io.jmix.core:jmix-core-starter'
implementation 'io.jmix.data:jmix-eclipselink-starter'
implementation 'io.jmix.security:jmix-security-starter'
implementation 'io.jmix.security:jmix-security-flowui-starter'
implementation 'io.jmix.security:jmix-security-data-starter'
implementation 'io.jmix.localfs:jmix-localfs-starter'
implementation 'io.jmix.flowui:jmix-flowui-starter'
implementation 'io.jmix.flowui:jmix-flowui-data-starter'
implementation 'io.jmix.flowui:jmix-flowui-themes'
implementation 'io.jmix.datatools:jmix-datatools-starter'
implementation 'io.jmix.datatools:jmix-datatools-flowui-starter'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation("org.apache.spark:spark-core_2.13:3.5.0") {
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
exclude group: 'javax.servlet', module: '*'
exclude group: 'javax.servlet.jsp', module: '*'
exclude group: 'javax.ws.rs', module: '*'
exclude group: 'javax.xml.bind', module: '*'
exclude group: 'org.apache.logging.log4j', module: 'log4j-to-slf4j'
exclude group: 'org.apache.logging.log4j', module: 'log4j-slf4j2-impl'
}
implementation("org.apache.spark:spark-sql_2.13:3.5.0") {
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
exclude group: 'javax.servlet', module: '*'
exclude group: 'javax.servlet.jsp', module: '*'
exclude group: 'javax.ws.rs', module: '*'
exclude group: 'javax.xml.bind', module: '*'
exclude group: 'org.apache.logging.log4j', module: 'log4j-to-slf4j'
exclude group: 'org.apache.logging.log4j', module: 'log4j-slf4j2-impl'
}
runtimeOnly 'org.hsqldb:hsqldb'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation 'io.jmix.flowui:jmix-flowui-test-assist'
}
bootRun {
jvmArgs([
'--add-opens=java.base/java.lang=ALL-UNNAMED',
'--add-opens=java.base/java.lang.invoke=ALL-UNNAMED',
'--add-opens=java.base/java.lang.reflect=ALL-UNNAMED',
'--add-opens=java.base/java.io=ALL-UNNAMED',
'--add-opens=java.base/java.net=ALL-UNNAMED',
'--add-opens=java.base/java.nio=ALL-UNNAMED',
'--add-opens=java.base/java.util=ALL-UNNAMED',
'--add-opens=java.base/java.util.concurrent=ALL-UNNAMED',
'--add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED',
'--add-opens=java.base/sun.nio.ch=ALL-UNNAMED',
'--add-opens=java.base/sun.nio.cs=ALL-UNNAMED',
'--add-opens=java.base/sun.security.action=ALL-UNNAMED',
'--add-opens=java.base/sun.util.calendar=ALL-UNNAMED',
'--add-opens=java.security.jgss/sun.security.krb5=ALL-UNNAMED'
])
}
test {
useJUnitPlatform()
}
vaadin {
optimizeBundle = false
}
Thanks in Advance