forked from apache/linkis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
adb7f8e
commit dac4601
Showing
7 changed files
with
405 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...ark/src/main/java/org/apache/linkis/engineplugin/spark/datacalc/sink/DorisSinkConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package org.apache.linkis.engineplugin.spark.datacalc.sink; | ||
|
||
import org.apache.linkis.engineplugin.spark.datacalc.model.SinkConfig; | ||
|
||
import javax.validation.constraints.NotBlank; | ||
import javax.validation.constraints.Pattern; | ||
|
||
public class DorisSinkConfig extends SinkConfig { | ||
|
||
@NotBlank private String url; | ||
|
||
@NotBlank private String user; | ||
|
||
private String password; | ||
|
||
@NotBlank private String targetDatabase; | ||
|
||
@NotBlank private String targetTable; | ||
|
||
@NotBlank | ||
@Pattern( | ||
regexp = "^(overwrite|append|ignore|error|errorifexists)$", | ||
message = | ||
"Unknown save mode: {saveMode}. Accepted save modes are 'overwrite', 'append', 'ignore', 'error', 'errorifexists'.") | ||
private String saveMode = "overwrite"; | ||
|
||
public String getUrl() { | ||
return url; | ||
} | ||
|
||
public void setUrl(String url) { | ||
this.url = url; | ||
} | ||
|
||
public String getUser() { | ||
return user; | ||
} | ||
|
||
public void setUser(String user) { | ||
this.user = user; | ||
} | ||
|
||
public String getPassword() { | ||
return password; | ||
} | ||
|
||
public void setPassword(String password) { | ||
this.password = password; | ||
} | ||
|
||
public String getTargetDatabase() { | ||
return targetDatabase; | ||
} | ||
|
||
public void setTargetDatabase(String targetDatabase) { | ||
this.targetDatabase = targetDatabase; | ||
} | ||
|
||
public String getTargetTable() { | ||
return targetTable; | ||
} | ||
|
||
public void setTargetTable(String targetTable) { | ||
this.targetTable = targetTable; | ||
} | ||
|
||
public String getSaveMode() { | ||
return saveMode; | ||
} | ||
|
||
public void setSaveMode(String saveMode) { | ||
this.saveMode = saveMode; | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...src/main/java/org/apache/linkis/engineplugin/spark/datacalc/source/DorisSourceConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package org.apache.linkis.engineplugin.spark.datacalc.source; | ||
|
||
import org.apache.linkis.engineplugin.spark.datacalc.model.SourceConfig; | ||
|
||
import javax.validation.constraints.NotBlank; | ||
|
||
public class DorisSourceConfig extends SourceConfig { | ||
|
||
@NotBlank private String url; | ||
|
||
@NotBlank private String user; | ||
private String password; | ||
|
||
@NotBlank private String sourceDatabase; | ||
|
||
@NotBlank private String sourceTable; | ||
|
||
public String getUrl() { | ||
return url; | ||
} | ||
|
||
public void setUrl(String url) { | ||
this.url = url; | ||
} | ||
|
||
public String getUser() { | ||
return user; | ||
} | ||
|
||
public void setUser(String user) { | ||
this.user = user; | ||
} | ||
|
||
public String getPassword() { | ||
return password; | ||
} | ||
|
||
public void setPassword(String password) { | ||
this.password = password; | ||
} | ||
|
||
public String getSourceDatabase() { | ||
return sourceDatabase; | ||
} | ||
|
||
public void setSourceDatabase(String sourceDatabase) { | ||
this.sourceDatabase = sourceDatabase; | ||
} | ||
|
||
public String getSourceTable() { | ||
return sourceTable; | ||
} | ||
|
||
public void setSourceTable(String sourceTable) { | ||
this.sourceTable = sourceTable; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...s/spark/src/main/scala/org/apache/linkis/engineplugin/spark/datacalc/sink/DorisSink.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package org.apache.linkis.engineplugin.spark.datacalc.sink | ||
|
||
import org.apache.linkis.common.utils.Logging | ||
import org.apache.linkis.engineplugin.spark.datacalc.api.DataCalcSink | ||
|
||
import org.apache.commons.lang3.StringUtils | ||
import org.apache.spark.sql.{Dataset, Row, SparkSession} | ||
|
||
import scala.collection.JavaConverters._ | ||
|
||
class DorisSink extends DataCalcSink[DorisSinkConfig] with Logging { | ||
|
||
def output(spark: SparkSession, ds: Dataset[Row]): Unit = { | ||
var options = Map( | ||
"doris.fenodes" -> config.getUrl, | ||
"user" -> config.getUser, | ||
"password" -> config.getPassword, | ||
"doris.table.identifier" -> String.format( | ||
"%s.%s", | ||
config.getTargetDatabase, | ||
config.getTargetTable | ||
) | ||
) | ||
|
||
if (config.getOptions != null && !config.getOptions.isEmpty) { | ||
options = config.getOptions.asScala.toMap ++ options | ||
} | ||
|
||
val writer = ds.write.format("doris") | ||
if (StringUtils.isNotBlank(config.getSaveMode)) { | ||
writer.mode(config.getSaveMode) | ||
} | ||
|
||
logger.info( | ||
s"Save data from doris url: ${config.getUrl}, targetDatabase: ${config.getTargetDatabase}, targetTable: ${config.getTargetTable}" | ||
) | ||
writer.options(options).save() | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
...ark/src/main/scala/org/apache/linkis/engineplugin/spark/datacalc/source/DorisSource.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package org.apache.linkis.engineplugin.spark.datacalc.source | ||
|
||
import org.apache.linkis.common.utils.Logging | ||
import org.apache.linkis.engineplugin.spark.datacalc.api.DataCalcSource | ||
|
||
import org.apache.spark.sql.{Dataset, Row, SparkSession} | ||
|
||
class DorisSource extends DataCalcSource[DorisSourceConfig] with Logging { | ||
|
||
override def getData(spark: SparkSession): Dataset[Row] = { | ||
val reader = spark.read.format("doris") | ||
|
||
if (config.getOptions != null && !config.getOptions.isEmpty) { | ||
reader.options(config.getOptions) | ||
} | ||
|
||
logger.info( | ||
s"Load data from Doris url: ${config.getUrl}, sourceDatabase: ${config.getSourceDatabase}, sourceTable: ${config.getSourceTable}" | ||
) | ||
|
||
reader | ||
.option( | ||
"doris.table.identifier", | ||
String.format("%s.%s", config.getSourceDatabase, config.getSourceTable) | ||
) | ||
.option("doris.fenodes", config.getUrl) | ||
.option("user", config.getUser) | ||
.option("password", config.getPassword) | ||
.load() | ||
} | ||
|
||
} |
Oops, something went wrong.