import java.text.SimpleDateFormat import java.time.format.{DateTimeFormatter, TextStyle} import java.time.{Instant, LocalDate, LocalDateTime, YearMonth} import java.util.{Calendar, Date, Locale} import java.sql.{Connection, Timestamp} import java.time.Instant object HelloWorld { def toPascalCase(str: String): String = { val r = str.replaceAll("[\\/.,&()–-]", " ") val t = r.replaceAll("\\s{2,}", " ") t.split(" ").map(_.toLowerCase.capitalize).mkString("_") } def toTitleCase(str: String): String = { val folderName = this.getClass.getSimpleName.stripSuffix("$") print(folderName) var s = str.replaceAll("_"," ") val s0 = s.split("\\s{2,}").map(_.toLowerCase.capitalize).mkString(" ") val s1 = s0.split(" ").map(_.toLowerCase.capitalize).mkString("_") val s2 = s1.split("-").map(_.capitalize).mkString("-") var s3 = s2.split("\\.").map(_.capitalize).mkString(".") s3.split("\\(").map(_.capitalize).mkString("(") } def camelToSnake(str: String): String = { str.replaceAll("([a-z])([A-Z])", "$1_$2") .replaceAll("([A-Z])([A-Z][a-z])", "$1_$2") .toLowerCase } val col_name="TotalErrTrxCnt" println(camelToSnake(col_name)) // s2.split(" ").map { word => // if (word.endsWith(".")) word // else word.capitalize // }.mkString(" ") println("Okay") println(LocalDate.now()) val list1 = List("ABU DHABI COMMERCIAL BANK", "ADYEN N.V.", "AIB GROUP (UK) P.L.C.", "ALLIED IRISH BANKS, P.L.C.", "ARUBA BANK N.V.", "ARVEST BANK", "AVIDIA BANK", "AXIOM BANK", "Bank of America (BAMS - excl Home Depot)", "Bank of America (Fiserv)", "Bank of America (only Home Depot)", "BANK OF AMERICA EUROPE DAC", "BANK OF AMERICA, NA ACQUIRING MERCHANT SERVICES", "BANK OF AMERICA, NATIONAL ASSOCIATION", "BANK OF HAWAII", "BARCLAYS BANK PLC", "BAYCOAST BANK", "BLOM BANK S.A.L.", "BMO Harris Bank", "BNP PARIBAS", "BOKF, NATIONAL ASSOCIATION", "BPCE", "CAPITAL ONE, NATIONAL ASSOCIATION", "CBW BANK", "CENTRAL BANK & TRUST CO.", "Chase PaymenTech", "CHASE PAYMENTECH EUROPE LIMITED", "CHESAPEAKE BANK", "Citibank", "CITIBANK, NATIONAL ASSOCIATION", "COMERICA BANK", "COMMERCE BANK", "COMMERCIAL BANK OF CALIFORNIA", "COMMUNITY FEDERAL SAVINGS BANK", "CROSS RIVER BANK", "DEUTSCHE BANK AG", "Elavon", "ELAVON FINANCIAL SERVICES DESIGNATED ACTIVITY COMPANY", "EQUITABLE BANK", "ESQUIRE BANK, NATIONAL ASSOCIATION", "EVO Payments (Deutsche)", "EVO Payments (Wells)", "EVOLVE BANK & TRUST", "FIFTH THIRD MB FINANCIAL", "FIRST DATA EUROPE LTD", "FIRST DATA GMBH", "FIRST DATA MERCHANT SOLUTIONS (HONG KONG) PRIVATE LIMITED", "FIRST DATA MERCHANT SOLUTIONS (MALAYSIA) SDN BHD", "FIRST DATA MERCHANT SOLUTIONS AUSTRALIA PTY LTD", "FIRST DATA MERCHANT SOLUTIONS PRIVATE LIMITED", "FIRST HAWAIIAN BANK", "FIRST NATIONAL BANK OF OMAHA", "FIRST-CITIZENS BANK & TRUST COMPANY", "FIRST-CITIZENS BANK & TRUST COMPANY - SVB", "FIRSTBANK PUERTO RICO", "FIS WORLDPAY (MALAYSIA) SDN. BHD.", "Fresno First Bank", "FULTON BANK, NATIONAL ASSOCIATION", "GPC FINANCIAL CORPORATION", "GPUK LLP", "HANCOCK WHITNEY BANK", "J.P. MORGAN WHOLESALE PAYMENTS EUROPE LIMITED", "JPMORGAN CHASE BANK, NA - CANADA ACQUIRING", "JPMORGAN CHASE BANK, NATIONAL ASSOCIATION", "KeyBank National Association (Merchant E)", "KeyBank National Association (other BINs)", "LLOYDS BANK PLC", "Manufacturers and Trade", "MAYA PHILIPPINES, INC.", "MERRICK BANK", "METROPOLITAN COMMERCIAL BANK", "MISSION VALLEY BANK", "MVB BANK, INC", "NATIONAL AUSTRALIA BANK LIMITED", "NAVY FEDERAL CREDIT UNION", "NCMIC FINANCE CORPORATION", "NETS DENMARK A/S", "NETWORK INTERNATIONAL LLC", "NORTH AMERICAN BANKING COMPANY", "NUVEI TECHNOLOGIES CORP", "ORCO BANK N.V.", "PATHWARD, N.A.", "PEOPLES TRUST COMPANY", "PNC Bank", "PNC Bank(other BINs)", "ROYAL BANK OF CANADA", "Santander Bank", "SHANGHAI COMMERCIAL BANK LIMITED", "SOUTH STATE BANK, NATIONAL ASSOCIATION", "SSB BANK", "SUNTRUST BANK", "Synovus Bank (APPs)", "Synovus Bank (Card Connect)", "Synovus Bank (CELERO)", "Synovus Bank (Merchant E)", "Synovus Bank (other BINs)", "Synovus Bank (PRTH)", "Synovus Bank (Qualpay)", "Synovus Bank (Talus)", "Synovus Bank (TSYS)", "Synovus Bank (Wind River)", "TD BANK, NATIONAL ASSOCIATION", "The Bancorp Bank - EPX", "THE CENTRAL TRUST BANK", "THE DART BANK", "THE FIDELITY BANK", "THE HUNTINGTON NATIONAL BANK", "THE PUEBLO BANK AND TRUST COMPANY", "Truist", "U.S. BANK NATIONAL ASSOCIATION", "UMPQUA BANK", "US Bank", "VERMONT STATE BANK", "VIETNAM PROSPERITY JOINT STOCK COMMERCIAL BANK", "Wells (Alliance)", "Wells (Heartland_Global Payment)", "Wells (Merchant E)", "Wells (Non-Alliance)", "Wells (remaining BINs)", "Wells (Stripe)", "Wells (TSYS)", "WEPAY PAYMENTS LTD.", "WESTAMERICA BANK", "WOODFOREST NATIONAL BANK", "WORLDLINE S.A.", "Worldpay - Fifth Third", "Worldpay – Capital One", "Worldpay – Citizens", "WORLDPAY (NZ) LIMITED", "WORLDPAY (UK) LIMITED", "WORLDPAY BESLOTEN VENNOOTSCHAP") // val input = "ASIA-PACIFIC REGION" // val pascalCase = toPascalCase(input.replaceAll("[ ()–-]", " ")) // val titleCase = toTitleCase(input) list1.foreach(item => { // do something with item // println(toPascalCase(item)) // println(toTitleCase(item)) }) // println(pascalCase) // prints "Hello_World" // println(toTitleCase(input)) // prints "Hello_World" def main(args: Array[String]): Unit = { // val obj = new String("Hello World") // println(this.getClass.getSimpleName) // println(this.getClass) val currentDate = LocalDate.now() val formatter = DateTimeFormatter.ofPattern("yyyyMM") val yyyyMMFormatter = DateTimeFormatter.ofPattern("yyyyMM") val yyyyMMddFormatter = DateTimeFormatter.ofPattern("yyyyMMdd") val MMddyyyyFormatter = DateTimeFormatter.ofPattern("MM/dd/yyyy") val reportDate="202406" val previousMonthReportDate = YearMonth.parse(reportDate, yyyyMMFormatter).minusMonths(1).format(yyyyMMFormatter) val startDtStr = YearMonth.parse(reportDate, yyyyMMFormatter).atDay(1).format(MMddyyyyFormatter) val endDtStr = YearMonth.parse(reportDate, yyyyMMFormatter).atEndOfMonth().format(MMddyyyyFormatter) val startOfMonth = YearMonth.parse(reportDate, yyyyMMFormatter).atDay(1).format(yyyyMMddFormatter) val endOfMonth = YearMonth.parse(reportDate, yyyyMMFormatter).atEndOfMonth().format(yyyyMMddFormatter) val tenthDayOfMonth = YearMonth.parse(reportDate, yyyyMMFormatter).atDay(10).format(yyyyMMddFormatter) // println(previousMonthReportDate) // println(startDtStr) // println(endDtStr) // println(startOfMonth) // println(endOfMonth) // println(tenthDayOfMonth) // val reportDate = currentDate.minusMonths(1).format(yyyyMMddFormatter) println(currentDate.minusMonths(1).format(yyyyMMddFormatter)) val acqrBid="10000646" val acqrNm="VISA_DQ-L3_10062327_Worldpay_–_Citizens_202401" println(acqrNm.replace("-","_")) val destinationPathtemp = s"""VISA_DQ-L3_${acqrBid}_${acqrNm}_${reportDate}.xlsx""".replaceAll("[ ()–-]", "_") println(destinationPathtemp) var dtPreviousMonth= "" var dtBeforePreviousMonth = "" def getDate: String = { val sdf = new SimpleDateFormat("yyyyMMdd") sdf.format(Calendar.getInstance.getTime) } def yyyyMMFormat(sdate:String): String = { val formatter = DateTimeFormatter.ofPattern("yyyyMM") YearMonth.parse(sdate, formatter).minusMonths(1).format(formatter) } def getCurrentTimeStamp: String = { val sdf = new SimpleDateFormat("yyyyMMddHHmmss") sdf.format(new Date) } // println(getCurrentTimeStamp) // def getFullCurrentTimeStamp: String = { // val sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.Z") // val sdf = new Date().getTime() // val sdf: String = new Timestamp(new Date().getTime()) // } val dtAdhocMonth = "202405" // val reportDate:String = "20240101" // val dtAdhocMonth = sparkConfigs.adhocmonth dtPreviousMonth = YearMonth.parse(dtAdhocMonth, yyyyMMFormatter).minusMonths(1).format(yyyyMMFormatter) dtBeforePreviousMonth = YearMonth.parse(dtAdhocMonth, yyyyMMFormatter).minusMonths(2).format(yyyyMMFormatter) dtPreviousMonth = currentDate.minusMonths(1).format(yyyyMMFormatter) dtBeforePreviousMonth = currentDate.minusMonths(2).format(yyyyMMFormatter) println(s"As adhoc flag is the report will be generated for ${dtPreviousMonth}") // println(getDate) // println(yyyyMMFormat(dtAdhocMonth)) // println(getFullCurrentTimeStamp) var startTs = new Timestamp(new Date().getTime()) // println(startTs) val currentTimestamp = Instant.now // println(currentTimestamp) // println(dtPreviousMonth) // println(dtBeforePreviousMonth) // val previousMonth = currentDate.minusMonths(1) // val beforePreviousMonth = currentDate.minusMonths(2) // var dtPreviousMonth = previousMonth.format(formatter) // val dtBeforePreviousMonth = beforePreviousMonth.format(formatter) // var dt = previousMonth.format(yyyyMMFormatter) // val mxCpdDt = "20240501" // val spreviousMonth = mxCpdDt.format(DateTimeFormatter.ofPattern("yyyyMM")) // // println(spreviousMonth) // var mxCpdDtYearMonth = mxCpdDt.format(yyyyMMFormatter) // var lastMonthYearMonth = LocalDate.now().minusMonths(1).format(yyyyMMFormatter) // val startDt = LocalDate.parse(dt + "01", yyyyMMddFormatter).withDayOfMonth(1) // val endDt = startDt.plusMonths(1).minusDays(1) // val startDtStr = startDt.format(MMddyyyyFormatter) // val endDtStr = endDt.format(MMddyyyyFormatter) // val startDtStr = YearMonth.parse(reportDate, yyyyMMFormatter) // .atDay(10).format(MMddyyyyFormatter) // println(startDtStr) // var acqrNm = "Elavon" // var acqrBid = "10025855" // val masterData = Seq((acqrNm + " (BID " + acqrBid + ") ", startDtStr + " - " + endDtStr)) // println(masterData) // println(dtBeforePreviousMonth) // println(currentDate) // println(dtPreviousMonth) // println(dt) // println(mxCpdDtYearMonth) // println(lastMonthYearMonth) // println(startDt) // println(endDt) // println(startDtStr) // println(endDtStr) // val text = sc.textFile("/Users/sidayala/Downloads/hive-license.txt") // val counts = text.flatMap(line => line.split(" ") // ).map(word => (word,1)).reduceByKey(_+_).counts.collect // println(counts) // val list = List("Anish is working on BigData Technologies","Hello Anish","BigData") // val thisString = "Spark application can be developed by using Spark Scala, Python Spark, Java and R" // val flatMapList = list.flatMap(x => x.split(" ")) // val flatMapString = thisString.split(" ") // val keyData = flatMapList.map(x => (x,1)) // val keyData2 = flatMapString.map(x => (x,1)) // val groupedList = keyData.groupBy(_._1) // val groupedString = keyData2.groupBy(_._1) // val result = groupedList.mapValues(list=>{ // list.map(_._2).sum // }) // result.foreach(println) // println() // val result2 = groupedString.mapValues(list=>{ // list.map(_._2).sum // }) // result2.foreach(println) // val arr = Array("b,2", "a,1", "c,3") // val sortedArr = arr.sortBy(item => item.split(",")(0)) // sortedArr.foreach(println) } }
Write, Run & Share Scala code online using OneCompiler's Scala online compiler for free. It's one of the robust, feature-rich online compilers for Scala language, running on the latest version 2.13.8. Getting started with the OneCompiler's Scala compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as Scala
and start coding.
OneCompiler's Scala online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample Scala program which takes name as input and prints hello message with your name.
object Hello {
def main(args: Array[String]): Unit = {
val name = scala.io.StdIn.readLine() // Read input from STDIN
println("Hello " + name )
}
}
Scala is both object-oriented and functional programming language by Martin Odersky in the year 2003.
Variable is a name given to the storage area in order to identify them in our programs.
var or val Variable-name [: Data-Type] = [Initial Value];
If, If-else, Nested-Ifs are used when you want to perform a certain set of operations based on conditional expressions.
if(conditional-expression){
//code
}
if(conditional-expression) {
//code if condition is true
} else {
//code if condition is false
}
if(condition-expression1) {
//code if above condition is true
} else if (condition-expression2) {
//code if above condition is true
}
else if(condition-expression3) {
//code if above condition is true
}
...
else {
//code if all the above conditions are false
}
For loop is used to iterate a set of statements based on a criteria.
for(index <- range){
// code
}
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while(condition) {
// code
}
Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.
do {
// code
} while (condition)
Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increases re-usuability and modularity.
def functionname(parameters : parameters-type) : returntype = { //code
}
You can either use =
or not in the function definition. If =
is not present, function will not return any value.