问:
Create loop to subset data by month and year
UPDATE: I have added the dput() input at the bottom of the post.

I have a large dataset of tweets that I would like to subset by month and year.

data_cleaning$date <- as.Date(data_cleaning$created_at, tryFormats = c("%Y-%m-%d", "%Y/%m/%d"), optional = FALSE)

I used the line of code above to format the date variable in the dataframe below.

```<code>id        text                                                                date
1389598   Honored to receive the United Way Award                             2012-05-22
1586410   Joining @TamronHall at 2:15pm today to discuss my bipartisan bill   2013-12-18
138058    Leahy leads 58 senators in lttr to #SecDef Hage                     2013-12-21
1482508   On one anniversary of #Sandy                                        2013-10-29
526459    #SocSec and #Medicare are absolutely vital                          2012-02-02
687900    Check out #MadeInWi BomBoard of Whitewater                          2014-04-14
826551    Congratulations to all of the hard-working @UTSA students           2013-12-21
1409462   Great to see so many proud Colombians                               2012-07-21
1807754   It is our duty to look after our veterans.                          2012-05-28
138057    Leahy presses preserv. of #TotalArmy capability                     2013-12-21
</code>```

I know how to manually create a subset by month with the following code:

```<code>data_cleaning <-  data_cleaning %>% filter(date >= "2012-01-1")
data_cleaning <-  data_cleaning %>% filter(date <= "2012-02-1")
</code>```

But I have 15 years worth of tweets that I would like to create a loop to subset this data by month and year, such that I have separate files for each. For example, ideally, I'd like to have files called "tweets_Jan2012", tweets_Feb2012, tweets_Mar2012", and so on, for each month that appears in the dataset.

Any help would be greatly appreciated.

```<code>Show in New WindowClear OutputExpand/Collapse Output
structure(list(author_id = c("242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999"), text = c("anyon feel unsaf home time alon confidenti help avail even re social distanc https t co jkmayado",
"actual think rue day decid tri intimid major backfir bravo michael https t co sidonllehr",
"congratul michaelemann first rate scientist fearless amp resolut remorseless attack fossil fuel forc https t co uyleddecm",
"today last day rhode island can sign health insur healthsourceri s special enrol period covid look option getcov https t co gkdyasc",
"april th https t co gskujfum", "translat hey captur court fair squar s want re go threaten point https t co ngtcofm",
"btw s coincid winner partisan decis big republican donor interest wsjopinion page alway flack",
"s hard defend dark money prowl around court inde s indefens defens pretend s happen amp just ignor fact overview under problem read https t co bkxvoyyndi",
"appreci shoutout whitehous effect s control suprem court look instead dark money fedsoc select justic dark money judicialnetwork s role confirm justic amp case win record republican donor https t co cxfqfzf",
"imposs burger https t co rtbbfqjbap", "question politico playbook ask present answer reconven senat https t co esnzuwqj",
"tomorrow last day healthsourceri s covid special enrol period uninsur rhode island can sign https t co kyuvaj",
"signal anyth anyon hello interest fund mitch mcconnel amp parti fund dark money machin surround amp stock suprem court obedi court will unpopular thing can t make elect republican https t co zjpfhvbua",
"markpatinkin man roll amaz https t co lbqag", "think corpor greedi check million plus dollar incom individu extract averag million care coronavirus bill took hospit got https t co kfuidhx",
"prioriti protocol senat oper safe push judg big donor fund judici influenc machin republican parti",
"trump nomin walker second power court nation walker s qualif near press appear defend buddi kavanaugh amp track record zealotri support republican parti polit goal like kill aca https t co nnmkvwgc",
"mcconnel delay covid relief bill fli kentucki brett kavanaugh celebr yet anoth unqualifi partisan trump judg justin walker https t co ovquouv",
"small bank still boil mad custom shoulder asid big bank second ppp round power superior autom sba fix happen right amp fair",
"ad ppp money meet need small busi particular small bank amp credit union got push asid big bank now big bank jam system autom applic frustrat small bank sbagov need fix",
"truth law got way even republican appoint justic couldn t stomach deliv big win gun manufactur isn t https t co ngtcofm",
"nra huge republican donor interest didn t get want suprem court right wing donor interest machin kick high gear get justic back line wsjopinion take lead cours https t co goiuipzcb",
"want abl safe reopen key test https t co ytmjalmvd", "coronavirus warn pdb repeat warn convey presid s daili brief alarm appear fail regist presid routin skip read pdb https t co cfsbemtn",
"great graphic nytim worth look well done https t co yqevgdh",
"imagin british paid peopl follow paul rever say british aren t come big hoax fake news can go back bed https t co mvqrxfi",
"climat scientist paul rever climat chang ring bell loud increas urgenc sinc s https t co eqjtsbknf",
"mood markwarn tuna melt d recommend tri rhode island s delici seafood instead mayo microwav requir https t co euojwft",
"thank break true mitch mcconnel special billion dollar special tax provis tuck last covid relief bill benefit millionair amp billionair https t co vimhica",
"ri great colleg univers deserv support thank brownunivers presid paxson https t co ubqmurtgfi",
"meanwhil right wing effort exact bring case front group support front group file amicus brief fund manipul crew lot turn case https t co lkhgypp",
"crack end republican justic gripe court s docket manipul https t co vcaaokwd",
"true one never know crew strong oppos seema verma unilater hurt rhode island hospit one cmsgov hhsgov abl defend https t co aavdutava",
"look like sorri episod will end decent note https t co yxgqkl",
"west warwick teacher make meet hero section https t co edhdkxoc",
"definit first time histori feder health agenc issu formal warn listen presid s offici https t co jbezonef",
"good night light adapt coronavirus start way say good night headlight emerg vehicl light hospit children get flashlight flash good night back s beauti thing even without coronavirus https t co mcggau",
"https t co btrocxmbau", "just anoth public servic whack job creepi dark money land oy https t co sonieqd",
"first need conquer enemi within corrupt anti scienc anti govern ideolog ordinarili kept aliv fring crank now foment massiv industri resent scientif check public oversight interfer money make https t co xlhcpuetp",
"heartbreak will back https t co qtggaeopvt", "mitch mcconnel say prioriti covid allow covid legisl bear mind scam flood billion wealthi investor donor make million dollar year covid connect none https t co oeerchqhf",
"davidcicillin alexthomasdc mzanona sarahnferri heatherscop seungminkim jenhab elistokol markzbarabak mffisher roigfranzia timcarman olgamassov maurajudki laurahayesdc scottagilmor megetz jeffreynpark lisabono afreedma annmmaloney lottieanddoof kfleisher bjeanclement jbonn patijinich jkfrel ericmgarcia emilyaheil mrdanzak juliajfish aaronsfish edmet joelachenbach davidvondrehl abcarianlat chrismegerian davidlaut raineytim ec schneider theodoricmey jdawsey noahbierman ddiamond rachanadixit name perfect movi nomin peopl godfath casablanca blaze saddl butch cassidi sundanc kid darkest hour jimlangevin peterneronha neildsteinberg dawneuer jamesdiossa",
"republican snuck billion millionairesgiveaway pandem relief bill even though noth fight covid replloyddoggett amp introduc legisl repeal shame tax break amp ensur aid goe american need https t co csyldjqgn",
"friend talk treat coronavirus lysol inject lung worri https t co ymjlzmrtj",
"friend exhibit kind behavior worri https t co puoicxw", "pelosi even make mask look cool win mcname getti imag https t co obbxzvujg",
"good night earth https t co dlcuyunow", "pope franci see natur tragedi earth s respons maltreat ad sin earth neighbor end creator time clean act https t co lrkynccunk",
"markpatinkin found moment chronicl coronavirus hero anoth amaz piec hope get pulitz https t co kmihfuzuu",
"serious mitch mcconnel want get state declar bankruptci d better get economist fed treasuri tell look like economi https t co pvhfqoymc",
"republican gave million dollar tax break millionair vital covid relief packag s time regular american get check",
"hell republican think jam high incom big donor link covid giveaway follow money https t co xqjpstjnxp",
"ag threaten governor fight keep citizen safe covid doj serious go sue state tri protect citizen https t co ifzmlkzyd",
"earth hero earth day thank billmckibben https t co kdvpav",
"ps corpor america overal noth congress fossil fuel mischief continu big compani thing want climat effort trade associ good net result corpor america oppos congress climat action time fix",
"corrupt america s govern near evil pollut planet ocean must stop",
"can make earth day promis reclaim healthi earth reclaim healthi polit expos throw crook dark money fake scienc phoni front group apparatus restor democraci work",
"fossil fuel industri live subsidi measur intern monetari fund north billion per year u s give industri massiv incent corrupt polit citizen unit robert five gave tool",
"bipartisanship climat stop dead lost decad fossil fuel fake scienc dark money phoni front group built whole apparatus web denial lie cheat bulli industri scale work",
"januari infam citizen unit decis present unlimit polit spend inde unlimit anonym polit spend fossil fuel industri instant use new power corrupt polit",
"earth day s good rememb lot good bipartisan climat legisl senat republican presidenti nomine solid climat platform",
"serious carbon price stop warm heat amp acidif co", "rememb earth day ocean day can start pass marin plastic bill sos ocean data bill blue globe amp real dollar ocean coastal fund nocsf https t co jryavxcb",
"re serious solut model tool can help get us safe climat republican even meet won t solv climat without break corrupt grip fossil fuel parti spoiler carbon price work https t co kfhuttiav",
"happi earthday free globe fossil fuel corrupt https t co rsshjcf",
"trump administr promis march th near month ago million coronavirus test conduct u s s april st haven t reach million test https t co eoioxyj",
"today pledg continu fight antisemit amp educ everyon holocaust never happen holocaustremembranceday",
"get serious renew energi can creat million good stabl job american current work oil amp gas can transit",
"let s clear s less fossil fuel corpor pillar economi fossil fuel donor central pillar republican fundrais henc parti s creepi crawl obedi fossil fuel interest https t co ddovmoii",
"senschum just now https t co dlnvvpem", "thank jimlangevin davidcicillin hous stand firm back get way improv posit",
"sba hospit test s unfortun mitch insist jam us negoti get big victori insist bipartisanship worth wait",
"faint heart panick misl mitch mcconnel tri jam us sba fund prepar much better bill",
"throw taxpay dollar behind compani expos economi massiv crash risk realli bad idea s m team brianschatz call federalreserv consid climat risk emerg lend program https t co kojqmrl",
"still clear direct trump administr money state money educ remain money hospit etc seem like long damn time sinc pass bill s holdup",
"top straight b giveaway million dollar plus earner republican snuck care s problem need fix money need flow actual small busi worker https t co zhyvmjco",
"proud polari mep ritin other organ help crisi https t co fwpmrhsap run group busi look purchas suppli mask includ product ri s world class textil compani https t co ktrasoevo",
"perhap newspap check rhode island s hospit wisdom cut loos negoti go sba https t co nwkjtxjta",
"republican pretend isn t true preserv flow fossil fuel industri money depend https t co xutocwmwv",
"happen climat disast take place time coronavirus will learn hear warn https t co gfoxydnra",
"oh come re put chuck schumer categori mitch mcconnel serious https t co fwirvmjjw",
"crash number mani marin speci rais price survivor high hunt feroci marin protect essenti stop spiral https t co badbghw",
"still come learn anyth listen warn https t co bzegjn", "happen happen partisan decis suprem court mani mani advanc big republican donor interest https t co ghwhhwewlw",
"health care worker plead person protect equip keep amp patient safe need presid talk less amp getuspp https t co uptrrbt",
"happen trump administr catastroph fail feder coordin leadership everi minut governor health care provid spend tumult wast time better spent problem https t co ikswhfnug",
"net meter help reduc wast fight climat chang keep cost consum ferc act swift reject shadi front group petit make net meter harder https t co uadxpkivi",
"hah somebodi els agre corrupt anti govern anti scienc patholog virus bodi polit thank maxboot https t co gmtqmob",
"earli nation data point troubl racial dispar need research help rais alarm amp protect vulner communiti",
"proud join senwarren amp timkain legisl ensur hhsgov report vital racial amp demograph data test treatment amp fatal rate covid https t co miqseophbd",
"anyon care give odd mention climat chang advoc carbon price claim support sincer check bet flunk https t co qobnzxj",
"markpatinkin fabul job sing unsung hero hero https t co sxygmdreba",
"consensus price carbon emiss pollut free unfair hinder success climat crisi https t co euqvswdygv",
"hope panel will good faith bipartisan effort inform scienc best practic",
"accept presid trump s invit serv bipartisan panel charg determin guidelin safe restart american economi amid covid pandem https t co wiqygnahzh",
"confront covid amp reviv economi congress pass bill send resourc direct rier can find answer question cash payment health protect small busi relief program amp much websit https t co sjjunovzw https t co odhcokgut",
"white guy rifl trump sign woman chief execut lock new materi guy https t co mbxsdofp",
"excel piec immens talent janemayerny dark money fame mitch mcconnel polit dark money oper explain destroy anyth senat stand door corrupt goal https t co eypezjsi",
"didn t mean us https t co qlxzojkzv"), date = structure(c(18382,
18382, 18382, 18382, 18382, 18382, 18382, 18382, 18382, 18381,
18381, 18381, 18381, 18381, 18381, 18380, 18380, 18380, 18380,
18380, 18380, 18380, 18380, 18380, 18380, 18379, 18379, 18379,
18379, 18379, 18379, 18379, 18379, 18378, 18378, 18378, 18378,
18377, 18377, 18377, 18377, 18376, 18376, 18376, 18376, 18376,
18376, 18376, 18375, 18375, 18375, 18375, 18375, 18375, 18374,
18374, 18374, 18374, 18374, 18374, 18374, 18374, 18374, 18374,
18374, 18374, 18373, 18373, 18373, 18373, 18373, 18373, 18373,
18373, 18373, 18372, 18372, 18372, 18372, 18372, 18371, 18371,
18371, 18370, 18370, 18370, 18369, 18369, 18369, 18369, 18369,
18369, 18368, 18368, 18368, 18368, 18368, 18368, 18368, 18368
), class = "Date")), row.names = c(NA, -100L), class = c("data.table",
"data.frame"), .internal.selfref = <pointer: 0x7fac0a810ee0>)
</code>```

答:
You may want to consider making use of the nest function. Drawing on the following:

But I have 15 years worth of tweets that I would like to create a loop to subset this data by month and year, such that I have separate files for each.1

You can create a list of nested frames in the following manner:

```<code>library("tidyverse")
data_nested <- sample_data %>%
    mutate(year_month = format.Date(date, "%Y-%m")) %>%
    group_by(year_month) %>%
    nest()
</code>```

You can then save every single data frame to a separate CSV file using year_month value in the file name. This function can be easily manipulated if you want to add further elements to the file name.

```<code>map2(data_nested$data, data_nested$year_month,
     ~ write_csv(x = .x, file = paste0(.y, ".csv")))
</code>```

Notes

sample_data originates from the provided dput output; this data will result only in one file 2020-04.csv

1 You may want to explore group_by and nest functions as those are fairly efficient and may be more convenient than handling data via separate files. Finally for "big data" challenges, solutions like spark may be more efficient than having to loop over multiple files.

Body:
UPDATE: I have added the dput() input at the bottom of the post.

I have a large dataset of tweets that I would like to subset by month and year.

data_cleaning$date <- as.Date(data_cleaning$created_at, tryFormats = c("%Y-%m-%d", "%Y/%m/%d"), optional = FALSE)

I used the line of code above to format the date variable in the dataframe below.

id        text                                                                date
1389598   Honored to receive the United Way Award                             2012-05-22
1586410   Joining @TamronHall at 2:15pm today to discuss my bipartisan bill   2013-12-18
138058    Leahy leads 58 senators in lttr to #SecDef Hage                     2013-12-21
1482508   On one anniversary of #Sandy                                        2013-10-29
526459    #SocSec and #Medicare are absolutely vital                          2012-02-02
687900    Check out #MadeInWi BomBoard of Whitewater                          2014-04-14
826551    Congratulations to all of the hard-working @UTSA students           2013-12-21
1409462   Great to see so many proud Colombians                               2012-07-21
1807754   It is our duty to look after our veterans.                          2012-05-28
138057    Leahy presses preserv. of #TotalArmy capability                     2013-12-21

I know how to manually create a subset by month with the following code:

data_cleaning <-  data_cleaning %>% filter(date >= "2012-01-1")
data_cleaning <-  data_cleaning %>% filter(date <= "2012-02-1")

But I have 15 years worth of tweets that I would like to create a loop to subset this data by month and year, such that I have separate files for each. For example, ideally, I'd like to have files called "tweets_Jan2012", tweets_Feb2012, tweets_Mar2012", and so on, for each month that appears in the dataset.

Any help would be greatly appreciated.

Show in New WindowClear OutputExpand/Collapse Output
structure(list(author_id = c("242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999", "242555999", "242555999", "242555999",
"242555999", "242555999"), text = c("anyon feel unsaf home time alon confidenti help avail even re social distanc https t co jkmayado",
"actual think rue day decid tri intimid major backfir bravo michael https t co sidonllehr",
"congratul michaelemann first rate scientist fearless amp resolut remorseless attack fossil fuel forc https t co uyleddecm",
"today last day rhode island can sign health insur healthsourceri s special enrol period covid look option getcov https t co gkdyasc",
"april th https t co gskujfum", "translat hey captur court fair squar s want re go threaten point https t co ngtcofm",
"btw s coincid winner partisan decis big republican donor interest wsjopinion page alway flack",
"s hard defend dark money prowl around court inde s indefens defens pretend s happen amp just ignor fact overview under problem read https t co bkxvoyyndi",
"appreci shoutout whitehous effect s control suprem court look instead dark money fedsoc select justic dark money judicialnetwork s role confirm justic amp case win record republican donor https t co cxfqfzf",
"imposs burger https t co rtbbfqjbap", "question politico playbook ask present answer reconven senat https t co esnzuwqj",
"tomorrow last day healthsourceri s covid special enrol period uninsur rhode island can sign https t co kyuvaj",
"signal anyth anyon hello interest fund mitch mcconnel amp parti fund dark money machin surround amp stock suprem court obedi court will unpopular thing can t make elect republican https t co zjpfhvbua",
"markpatinkin man roll amaz https t co lbqag", "think corpor greedi check million plus dollar incom individu extract averag million care coronavirus bill took hospit got https t co kfuidhx",
"prioriti protocol senat oper safe push judg big donor fund judici influenc machin republican parti",
"trump nomin walker second power court nation walker s qualif near press appear defend buddi kavanaugh amp track record zealotri support republican parti polit goal like kill aca https t co nnmkvwgc",
"mcconnel delay covid relief bill fli kentucki brett kavanaugh celebr yet anoth unqualifi partisan trump judg justin walker https t co ovquouv",
"small bank still boil mad custom shoulder asid big bank second ppp round power superior autom sba fix happen right amp fair",
"ad ppp money meet need small busi particular small bank amp credit union got push asid big bank now big bank jam system autom applic frustrat small bank sbagov need fix",
"truth law got way even republican appoint justic couldn t stomach deliv big win gun manufactur isn t https t co ngtcofm",
"nra huge republican donor interest didn t get want suprem court right wing donor interest machin kick high gear get justic back line wsjopinion take lead cours https t co goiuipzcb",
"want abl safe reopen key test https t co ytmjalmvd", "coronavirus warn pdb repeat warn convey presid s daili brief alarm appear fail regist presid routin skip read pdb https t co cfsbemtn",
"great graphic nytim worth look well done https t co yqevgdh",
"imagin british paid peopl follow paul rever say british aren t come big hoax fake news can go back bed https t co mvqrxfi",
"climat scientist paul rever climat chang ring bell loud increas urgenc sinc s https t co eqjtsbknf",
"mood markwarn tuna melt d recommend tri rhode island s delici seafood instead mayo microwav requir https t co euojwft",
"thank break true mitch mcconnel special billion dollar special tax provis tuck last covid relief bill benefit millionair amp billionair https t co vimhica",
"ri great colleg univers deserv support thank brownunivers presid paxson https t co ubqmurtgfi",
"meanwhil right wing effort exact bring case front group support front group file amicus brief fund manipul crew lot turn case https t co lkhgypp",
"crack end republican justic gripe court s docket manipul https t co vcaaokwd",
"true one never know crew strong oppos seema verma unilater hurt rhode island hospit one cmsgov hhsgov abl defend https t co aavdutava",
"look like sorri episod will end decent note https t co yxgqkl",
"west warwick teacher make meet hero section https t co edhdkxoc",
"definit first time histori feder health agenc issu formal warn listen presid s offici https t co jbezonef",
"good night light adapt coronavirus start way say good night headlight emerg vehicl light hospit children get flashlight flash good night back s beauti thing even without coronavirus https t co mcggau",
"https t co btrocxmbau", "just anoth public servic whack job creepi dark money land oy https t co sonieqd",
"first need conquer enemi within corrupt anti scienc anti govern ideolog ordinarili kept aliv fring crank now foment massiv industri resent scientif check public oversight interfer money make https t co xlhcpuetp",
"heartbreak will back https t co qtggaeopvt", "mitch mcconnel say prioriti covid allow covid legisl bear mind scam flood billion wealthi investor donor make million dollar year covid connect none https t co oeerchqhf",
"davidcicillin alexthomasdc mzanona sarahnferri heatherscop seungminkim jenhab elistokol markzbarabak mffisher roigfranzia timcarman olgamassov maurajudki laurahayesdc scottagilmor megetz jeffreynpark lisabono afreedma annmmaloney lottieanddoof kfleisher bjeanclement jbonn patijinich jkfrel ericmgarcia emilyaheil mrdanzak juliajfish aaronsfish edmet joelachenbach davidvondrehl abcarianlat chrismegerian davidlaut raineytim ec schneider theodoricmey jdawsey noahbierman ddiamond rachanadixit name perfect movi nomin peopl godfath casablanca blaze saddl butch cassidi sundanc kid darkest hour jimlangevin peterneronha neildsteinberg dawneuer jamesdiossa",
"republican snuck billion millionairesgiveaway pandem relief bill even though noth fight covid replloyddoggett amp introduc legisl repeal shame tax break amp ensur aid goe american need https t co csyldjqgn",
"friend talk treat coronavirus lysol inject lung worri https t co ymjlzmrtj",
"friend exhibit kind behavior worri https t co puoicxw", "pelosi even make mask look cool win mcname getti imag https t co obbxzvujg",
"good night earth https t co dlcuyunow", "pope franci see natur tragedi earth s respons maltreat ad sin earth neighbor end creator time clean act https t co lrkynccunk",
"markpatinkin found moment chronicl coronavirus hero anoth amaz piec hope get pulitz https t co kmihfuzuu",
"serious mitch mcconnel want get state declar bankruptci d better get economist fed treasuri tell look like economi https t co pvhfqoymc",
"republican gave million dollar tax break millionair vital covid relief packag s time regular american get check",
"hell republican think jam high incom big donor link covid giveaway follow money https t co xqjpstjnxp",
"ag threaten governor fight keep citizen safe covid doj serious go sue state tri protect citizen https t co ifzmlkzyd",
"earth hero earth day thank billmckibben https t co kdvpav",
"ps corpor america overal noth congress fossil fuel mischief continu big compani thing want climat effort trade associ good net result corpor america oppos congress climat action time fix",
"corrupt america s govern near evil pollut planet ocean must stop",
"can make earth day promis reclaim healthi earth reclaim healthi polit expos throw crook dark money fake scienc phoni front group apparatus restor democraci work",
"fossil fuel industri live subsidi measur intern monetari fund north billion per year u s give industri massiv incent corrupt polit citizen unit robert five gave tool",
"bipartisanship climat stop dead lost decad fossil fuel fake scienc dark money phoni front group built whole apparatus web denial lie cheat bulli industri scale work",
"januari infam citizen unit decis present unlimit polit spend inde unlimit anonym polit spend fossil fuel industri instant use new power corrupt polit",
"earth day s good rememb lot good bipartisan climat legisl senat republican presidenti nomine solid climat platform",
"serious carbon price stop warm heat amp acidif co", "rememb earth day ocean day can start pass marin plastic bill sos ocean data bill blue globe amp real dollar ocean coastal fund nocsf https t co jryavxcb",
"re serious solut model tool can help get us safe climat republican even meet won t solv climat without break corrupt grip fossil fuel parti spoiler carbon price work https t co kfhuttiav",
"happi earthday free globe fossil fuel corrupt https t co rsshjcf",
"trump administr promis march th near month ago million coronavirus test conduct u s s april st haven t reach million test https t co eoioxyj",
"today pledg continu fight antisemit amp educ everyon holocaust never happen holocaustremembranceday",
"get serious renew energi can creat million good stabl job american current work oil amp gas can transit",
"let s clear s less fossil fuel corpor pillar economi fossil fuel donor central pillar republican fundrais henc parti s creepi crawl obedi fossil fuel interest https t co ddovmoii",
"senschum just now https t co dlnvvpem", "thank jimlangevin davidcicillin hous stand firm back get way improv posit",
"sba hospit test s unfortun mitch insist jam us negoti get big victori insist bipartisanship worth wait",
"faint heart panick misl mitch mcconnel tri jam us sba fund prepar much better bill",
"throw taxpay dollar behind compani expos economi massiv crash risk realli bad idea s m team brianschatz call federalreserv consid climat risk emerg lend program https t co kojqmrl",
"still clear direct trump administr money state money educ remain money hospit etc seem like long damn time sinc pass bill s holdup",
"top straight b giveaway million dollar plus earner republican snuck care s problem need fix money need flow actual small busi worker https t co zhyvmjco",
"proud polari mep ritin other organ help crisi https t co fwpmrhsap run group busi look purchas suppli mask includ product ri s world class textil compani https t co ktrasoevo",
"perhap newspap check rhode island s hospit wisdom cut loos negoti go sba https t co nwkjtxjta",
"republican pretend isn t true preserv flow fossil fuel industri money depend https t co xutocwmwv",
"happen climat disast take place time coronavirus will learn hear warn https t co gfoxydnra",
"oh come re put chuck schumer categori mitch mcconnel serious https t co fwirvmjjw",
"crash number mani marin speci rais price survivor high hunt feroci marin protect essenti stop spiral https t co badbghw",
"still come learn anyth listen warn https t co bzegjn", "happen happen partisan decis suprem court mani mani advanc big republican donor interest https t co ghwhhwewlw",
"health care worker plead person protect equip keep amp patient safe need presid talk less amp getuspp https t co uptrrbt",
"happen trump administr catastroph fail feder coordin leadership everi minut governor health care provid spend tumult wast time better spent problem https t co ikswhfnug",
"net meter help reduc wast fight climat chang keep cost consum ferc act swift reject shadi front group petit make net meter harder https t co uadxpkivi",
"hah somebodi els agre corrupt anti govern anti scienc patholog virus bodi polit thank maxboot https t co gmtqmob",
"earli nation data point troubl racial dispar need research help rais alarm amp protect vulner communiti",
"proud join senwarren amp timkain legisl ensur hhsgov report vital racial amp demograph data test treatment amp fatal rate covid https t co miqseophbd",
"anyon care give odd mention climat chang advoc carbon price claim support sincer check bet flunk https t co qobnzxj",
"markpatinkin fabul job sing unsung hero hero https t co sxygmdreba",
"consensus price carbon emiss pollut free unfair hinder success climat crisi https t co euqvswdygv",
"hope panel will good faith bipartisan effort inform scienc best practic",
"accept presid trump s invit serv bipartisan panel charg determin guidelin safe restart american economi amid covid pandem https t co wiqygnahzh",
"confront covid amp reviv economi congress pass bill send resourc direct rier can find answer question cash payment health protect small busi relief program amp much websit https t co sjjunovzw https t co odhcokgut",
"white guy rifl trump sign woman chief execut lock new materi guy https t co mbxsdofp",
"excel piec immens talent janemayerny dark money fame mitch mcconnel polit dark money oper explain destroy anyth senat stand door corrupt goal https t co eypezjsi",
"didn t mean us https t co qlxzojkzv"), date = structure(c(18382,
18382, 18382, 18382, 18382, 18382, 18382, 18382, 18382, 18381,
18381, 18381, 18381, 18381, 18381, 18380, 18380, 18380, 18380,
18380, 18380, 18380, 18380, 18380, 18380, 18379, 18379, 18379,
18379, 18379, 18379, 18379, 18379, 18378, 18378, 18378, 18378,
18377, 18377, 18377, 18377, 18376, 18376, 18376, 18376, 18376,
18376, 18376, 18375, 18375, 18375, 18375, 18375, 18375, 18374,
18374, 18374, 18374, 18374, 18374, 18374, 18374, 18374, 18374,
18374, 18374, 18373, 18373, 18373, 18373, 18373, 18373, 18373,
18373, 18373, 18372, 18372, 18372, 18372, 18372, 18371, 18371,
18371, 18370, 18370, 18370, 18369, 18369, 18369, 18369, 18369,
18369, 18368, 18368, 18368, 18368, 18368, 18368, 18368, 18368
), class = "Date")), row.names = c(NA, -100L), class = c("data.table",
"data.frame"), .internal.selfref = <pointer: 0x7fac0a810ee0>)

Body:
You may want to consider making use of the nest function. Drawing on the following:

But I have 15 years worth of tweets that I would like to create a loop to subset this data by month and year, such that I have separate files for each.1

You can create a list of nested frames in the following manner:

library("tidyverse")
data_nested <- sample_data %>%
    mutate(year_month = format.Date(date, "%Y-%m")) %>%
    group_by(year_month) %>%
    nest()

You can then save every single data frame to a separate CSV file using year_month value in the file name. This function can be easily manipulated if you want to add further elements to the file name.

map2(data_nested$data, data_nested$year_month,
     ~ write_csv(x = .x, file = paste0(.y, ".csv")))

Notes

sample_data originates from the provided dput output; this data will result only in one file 2020-04.csv

1 You may want to explore group_by and nest functions as those are fairly efficient and may be more convenient than handling data via separate files. Finally for "big data" challenges, solutions like spark may be more efficient than having to loop over multiple files.


来源: stackexchange

问:
Database design: Simplicity in query vs simplicity in schema
There is an assignments table, and every assignment has a target GUID and a serial number. There are two processes: one inserts assignments and another one queries them and executes them. Assignments for one target must be processed strictly in serial number order, without any gaps.

If there is a gap in serial numbers sequence, the executing process should wait for this gap to be filled before processing further assignments for this target

We identified two approaches to solve this.
The first one is to have a boolean flag "is_ready", and set it on each insert in the following way:

```<code>UPDATE assignments
SET is_ready = true
FROM (
    SELECT ROW_NUMBER () OVER (ORDER BY serial_number)
    FROM assignments
    WHERE target = <#address> and serial_number >= <#last_serial_number>
) AS subquery
WHERE
    subquery.serial_number=<#last_serial_number> + subquery.row_number and
    transactions.last_serial_number =  subquery.last_serial_number and
    transactions.target = subquery.target;
</code>```

Note that if there are any gaps, we only allow at most 5 assignments that are waiting (so the subquery will reutrn at most 5 rows)

Alternatively, we can have an integer field . It would represent the number of gaps in serial numbers for this target before current serial number. This way on insert we just have to update all the records with serial_number higher than the one being inserted:

```<code>UPDATE assignments
SET number_of_serial_gaps = number_of_serial_gaps - 1
WHERE target = <#address> AND serial_number >= <#last_serial_number>
</code>```

And then on SELECT we just have to check that number_of_serial_gaps == 0.

The first approach has (arguably) cleaner DB structure - just one boolean field, while the second approach has an advantage of requiring a simpler query.

Both ways would probably do and I think the difference is not substantial, however perhaps there are some stronger arguments on either side?

答:
This seems like a question of "How do I avoid a race condition while externally processing rows?"  Combined with the requirements of not missing any rows, and fault tolerance in case of failure or a hung process.

The answer to that question is more of a strategy than a specific how-to.  I would suggest that you look into using PostgreSQL custom locks to make the coordination.   This would allow you to work on the rows, not conflict with rows being worked on, and would be fault tolerant if the process acting on the rows ab-ends.

ContentLicense: CC BY-SA 4.0

Body:
There is an assignments table, and every assignment has a target GUID and a serial number. There are two processes: one inserts assignments and another one queries them and executes them. Assignments for one target must be processed strictly in serial number order, without any gaps.

If there is a gap in serial numbers sequence, the executing process should wait for this gap to be filled before processing further assignments for this target

We identified two approaches to solve this.
The first one is to have a boolean flag "is_ready", and set it on each insert in the following way:

UPDATE assignments
SET is_ready = true
FROM (
    SELECT ROW_NUMBER () OVER (ORDER BY serial_number)
    FROM assignments
    WHERE target = <#address> and serial_number >= <#last_serial_number>
) AS subquery
WHERE
    subquery.serial_number=<#last_serial_number> + subquery.row_number and
    transactions.last_serial_number =  subquery.last_serial_number and
    transactions.target = subquery.target;

Note that if there are any gaps, we only allow at most 5 assignments that are waiting (so the subquery will reutrn at most 5 rows)

Alternatively, we can have an integer field . It would represent the number of gaps in serial numbers for this target before current serial number. This way on insert we just have to update all the records with serial_number higher than the one being inserted:

UPDATE assignments
SET number_of_serial_gaps = number_of_serial_gaps - 1
WHERE target = <#address> AND serial_number >= <#last_serial_number>

And then on SELECT we just have to check that number_of_serial_gaps == 0.

The first approach has (arguably) cleaner DB structure - just one boolean field, while the second approach has an advantage of requiring a simpler query.

Both ways would probably do and I think the difference is not substantial, however perhaps there are some stronger arguments on either side?


问:
Laravel Eloquent Multiple 'WHERE NOT LIKE' Statements
I am trying to filter a users list to remove any test accounts with certain email extensions.

My query:

```<code>User::where('email', 'NOT LIKE', '%test.com')
    ->where('email', 'NOT LIKE', '%test1.com')
    ->where('email', 'NOT LIKE', '%test2.com')
    ->where('email', 'NOT LIKE', '%test3.com')
</code>```

I'm wondering if there's a better way to write this in one statement like whereNotIn but that doesn't seem to work. I'm looking for something like this:

```<code>User::whereNotLike('email', [
    '%test.com',
    '%test1.com',
    '%test2.com',
    '%test3.com',
]);
</code>```

答:
The only way to achieve what you want is to use regular expressions in the query.

Here's one that should catch all your use cases.

$users = User::whereRaw("email NOT REGEXP '?'", ['test[0-9]*.com$'])->get();
```
<p>Here's another one using your specific values.</p>
<pre class="lang-php prettyprint-override"><code>$endsWith = [
    'test.com$',
    'test1.com$',
    'test2.com$',
    'test3.com$',
];

$users = User::whereRaw("email NOT REGEXP '?'", [implode('|', $endsWith])->get();
</code>```

Body:
I am trying to filter a users list to remove any test accounts with certain email extensions.

My query:

User::where('email', 'NOT LIKE', '%test.com')
    ->where('email', 'NOT LIKE', '%test1.com')
    ->where('email', 'NOT LIKE', '%test2.com')
    ->where('email', 'NOT LIKE', '%test3.com')

I'm wondering if there's a better way to write this in one statement like whereNotIn but that doesn't seem to work. I'm looking for something like this:

User::whereNotLike('email', [
    '%test.com',
    '%test1.com',
    '%test2.com',
    '%test3.com',
]);

Body:
The only way to achieve what you want is to use regular expressions in the query.

Here's one that should catch all your use cases.

$users = User::whereRaw("email NOT REGEXP '?'", ['test[0-9]*.com$'])->get();

Here's another one using your specific values.

$endsWith = [
    'test.com$',
    'test1.com$',
    'test2.com$',
    'test3.com$',
];

$users = User::whereRaw("email NOT REGEXP '?'", [implode('|', $endsWith])->get();


问:
What is the alternative of "approve" in evm on Solana?
I have several wallets in evm. I give their X token access to my main wallet by calling Contract(x).approve() function. Thus i can make operations with these wallets. Now i want to do same thing on solana with solana web3 library. However i cannot find any function that gives allowance to my main wallet. The X token on Solana uses solana token program.</p>

答:
Correct, you cannot approve tokens using the normal @solana/web3.js package, so you'll have to use the @solana/spl-token package in one of two ways:

approve does it from the client (https://github.com/solana-labs/solana-program-library/blob/edec44180c3349abd77677acb2270a00121f2936/token/js/client/token.js#L905)

createApproveInstruction creates the instruction which you must include in a Transasction and then send (https://github.com/solana-labs/solana-program-library/blob/edec44180c3349abd77677acb2270a00121f2936/token/js/client/token.js#L1570)


问:
How to convert a list of characters that is stored in a single value (per record) into a format that can be analyzed? R
So I have the following data. In this dataframe I have a username, date, and a list of packages. My goal is to transform that column packages into a format I can analyze.

```<code>> print(data_example)
# A tibble: 4 x 3
  username date     packages
  <chr>    <chr>    <chr>
1 John     1/5/2015 "compiler 4.1.2, magrittr 2.0.1, ellipsis 0.3.2, tools 4.1.2, pillar 1.6.4"
2 Karen    1/5/2015 "compiler 4.1.2, tools 4.1.2\""
3 Mike     1/5/2015 "evaluate 0.14, highr 0.9, httr 1.4.2, pillar 1.6.4, rlang 0.4.12"
4 Zoe      1/6/2015 "httr 1.4.2, viridisLite 0.4.0, jsonlite 1.7.2, splines 4.1.2"
</code>```

I tried doing something like this but this doesn't really give me much value.

```<code>packages <- as.list(parsed_log$packages)
</code>```

My goal would be to try doing a "pivot longer" and get an outcome like this? I'm not sure if this is the best way to analyze this kind of data.

```<code>username   date      packages
John       1/5/2015  compiler 4.1.2
John       1/5/2015  magrittr 2.0.1
John       1/5/2015  ellipsis 0.3.2
John       1/5/2015  tools 4.1.2
ect...
</code>```

Body:
So I have the following data. In this dataframe I have a username, date, and a list of packages. My goal is to transform that column packages into a format I can analyze.

> print(data_example)
# A tibble: 4 x 3
  username date     packages
  <chr>    <chr>    <chr>
1 John     1/5/2015 "compiler 4.1.2, magrittr 2.0.1, ellipsis 0.3.2, tools 4.1.2, pillar 1.6.4"
2 Karen    1/5/2015 "compiler 4.1.2, tools 4.1.2\""
3 Mike     1/5/2015 "evaluate 0.14, highr 0.9, httr 1.4.2, pillar 1.6.4, rlang 0.4.12"
4 Zoe      1/6/2015 "httr 1.4.2, viridisLite 0.4.0, jsonlite 1.7.2, splines 4.1.2"

I tried doing something like this but this doesn't really give me much value.

packages <- as.list(parsed_log$packages)

My goal would be to try doing a "pivot longer" and get an outcome like this? I'm not sure if this is the best way to analyze this kind of data.

username   date      packages
John       1/5/2015  compiler 4.1.2
John       1/5/2015  magrittr 2.0.1
John       1/5/2015  ellipsis 0.3.2
John       1/5/2015  tools 4.1.2
ect...

Body:
A solution, based on tidyr::separate:

library(tidyr)

df <- data.frame(
  stringsAsFactors = FALSE,
  username = c("John", "Karen", "Mike", "Zoe"),
  date = c("1/5/2015", "1/5/2015", "1/5/2015", "1/6/2015"),
  packages = c("compiler 4.1.2, magrittr 2.0.1, ellipsis 0.3.2, tools 4.1.2, pillar 1.6.4","compiler 4.1.2, tools 4.1.2\\\"",
               "evaluate 0.14, highr 0.9, httr 1.4.2, pillar 1.6.4, rlang 0.4.12",
               "httr 1.4.2, viridisLite 0.4.0, jsonlite 1.7.2, splines 4.1.2")
)

separate_rows(df, packages, sep = ", ")

#> # A tibble: 16 × 3
#>    username date     packages
#>    <chr>    <chr>    <chr>
#>  1 John     1/5/2015 "compiler 4.1.2"
#>  2 John     1/5/2015 "magrittr 2.0.1"
#>  3 John     1/5/2015 "ellipsis 0.3.2"
#>  4 John     1/5/2015 "tools 4.1.2"
#>  5 John     1/5/2015 "pillar 1.6.4"
#>  6 Karen    1/5/2015 "compiler 4.1.2"
#>  7 Karen    1/5/2015 "tools 4.1.2\\\""
#>  8 Mike     1/5/2015 "evaluate 0.14"
#>  9 Mike     1/5/2015 "highr 0.9"
#> 10 Mike     1/5/2015 "httr 1.4.2"
#> 11 Mike     1/5/2015 "pillar 1.6.4"
#> 12 Mike     1/5/2015 "rlang 0.4.12"
#> 13 Zoe      1/6/2015 "httr 1.4.2"
#> 14 Zoe      1/6/2015 "viridisLite 0.4.0"
#> 15 Zoe      1/6/2015 "jsonlite 1.7.2"
#> 16 Zoe      1/6/2015 "splines 4.1.2"


问:
Create a leaflet map based on postal codes
I have the dataframe below:

```<code>mapd<-structure(list(City = c("Henderson", "Henderson", "Los Angeles",
"Fort Lauderdale", "Fort Lauderdale", "Los Angeles", "Los Angeles",
"Los Angeles", "Los Angeles", "Los Angeles"), State = c("Kentucky",
"Kentucky", "California", "Florida", "Florida", "California",
"California", "California", "California", "California"), Zip = c(42420,
42420, 90036, 33311, 33311, 90032, 90032, 90032, 90032, 90032
), Sales = c(261.96, 731.94, 14.62, 957.5775, 22.368, 48.86,
7.28, 907.152, 18.504, 114.9)), row.names = c(NA, -10L), class = c("tbl_df",
"tbl", "data.frame"))
</code>```

and I want to create a leaflet map that will display the Sales and City via markers. I guess that I need to use shapefiles data for us to do this and follow the logic like below but Im confused by the fact that I do not know where to find us shapefiles and also that I do not have latitude and longitude data.:

```<code>library(rgdal)
# Make sure the name of the shape file matches the name of the shape file
# from the ZIP archive
shp <- readOGR("geo_export_4e602fd1-be14-4590-8a68-fdbca198af8f.shp")

# Add count data
library(dplyr)
shp@data <- shp@data %>% left_join(mapd, by = c("zip" = "Zip"))
Example plot using leaflet.

library(leaflet)
leaflet(shp)
leaflet(data = shp) %>% addTiles() %>%
  addMarkers(~long, ~lat, popup = ~as.numeric(Sales), label = ~as.character(City))
</code>```

答:
Here is an option using zipcodeR (if you don't need to show the city extents with a polygon). You can get the latitude and longitude for each zipcode using geocode_zip, then join the lat and long data to your original dataframe, then use leaflet.

```<code>library(zipcodeR)
library(leaflet)
library(tidyverse)

mapd %>%
  left_join(.,
            geocode_zip(mapd$Zip) %>% mutate(zipcode = as.numeric(zipcode)),
            by = c("Zip" = "zipcode")) %>%
  leaflet() %>%
  addTiles() %>%
  addMarkers(
    ~ lng,
    ~ lat,
    popup = ~ as.character(Sales),
    label = ~ as.character(City)
  )
</code>```

Output

Body:
I have the dataframe below:

mapd<-structure(list(City = c("Henderson", "Henderson", "Los Angeles",
"Fort Lauderdale", "Fort Lauderdale", "Los Angeles", "Los Angeles",
"Los Angeles", "Los Angeles", "Los Angeles"), State = c("Kentucky",
"Kentucky", "California", "Florida", "Florida", "California",
"California", "California", "California", "California"), Zip = c(42420,
42420, 90036, 33311, 33311, 90032, 90032, 90032, 90032, 90032
), Sales = c(261.96, 731.94, 14.62, 957.5775, 22.368, 48.86,
7.28, 907.152, 18.504, 114.9)), row.names = c(NA, -10L), class = c("tbl_df",
"tbl", "data.frame"))

and I want to create a leaflet map that will display the Sales and City via markers. I guess that I need to use shapefiles data for us to do this and follow the logic like below but Im confused by the fact that I do not know where to find us shapefiles and also that I do not have latitude and longitude data.:

library(rgdal)
# Make sure the name of the shape file matches the name of the shape file
# from the ZIP archive
shp <- readOGR("geo_export_4e602fd1-be14-4590-8a68-fdbca198af8f.shp")

# Add count data
library(dplyr)
shp@data <- shp@data %>% left_join(mapd, by = c("zip" = "Zip"))
Example plot using leaflet.

library(leaflet)
leaflet(shp)
leaflet(data = shp) %>% addTiles() %>%
  addMarkers(~long, ~lat, popup = ~as.numeric(Sales), label = ~as.character(City))

Body:
Here is an option using zipcodeR (if you don't need to show the city extents with a polygon). You can get the latitude and longitude for each zipcode using geocode_zip, then join the lat and long data to your original dataframe, then use leaflet.

library(zipcodeR)
library(leaflet)
library(tidyverse)

mapd %>%
  left_join(.,
            geocode_zip(mapd$Zip) %>% mutate(zipcode = as.numeric(zipcode)),
            by = c("Zip" = "zipcode")) %>%
  leaflet() %>%
  addTiles() %>%
  addMarkers(
    ~ lng,
    ~ lat,
    popup = ~ as.character(Sales),
    label = ~ as.character(City)
  )

Output


问:
How run migrate in all schemas with Spring, Quarkus, Flyway, Hibernate, multitenancy?
Good morning, I'm trying to set up a QUARKUS project with flyway, hibernate, panache and multitenant.
But the script only runs once on the first schema, would anyone know how to run on the other schemas?

application.yml

```<code> datasource:
   db-kind: postgres
   username: postgres
   password: 1234
   jdbc:
     url: jdbc:postgresql://localhost:5432/postgres
     driver: org.postgresql.Driver
 hibernate-orm:
   multitenant: SCHEMA
   dialect: org.hibernate.dialect.PostgreSQLDialect
   log:
     sql: true
 flyway:
   migrate-at-start: true
   baseline-on-migrate: true
   baseline-version: 1.0.0
   create-schemas: true
   clean-at-start: true
   schemas: maripa, bicas, rhino
   locations: db/migration/maripa, db/migration/bicas, db/migration/rhino
</code>```

LOG

```<code>    __  ____  __  _____   ___  __ ____  ______
 --/ __ \/ / / / _ | / _ \/ //_/ / / / __/
 -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \
--\___\_\____/_/ |_/_/|_/_/|_|\____/___/
2021-03-09 07:41:54,213 INFO  [io.qua.fly.FlywayProcessor] (build-13) Adding application migrations in path '/home/idd_acosta/freelas/rhino/rhino-api/target/classes/db/migration/maripa/' using protocol 'file'
2021-03-09 07:41:54,844 INFO  [io.qua.arc.pro.BeanProcessor] (build-8) Found unrecommended usage of private members (use package-private instead) in application beans:
    - @Inject field br.com.rhino.user.mapper.RoleMapperImpl#permissionMapper,
    - @Inject field br.com.rhino.user.mapper.UserMapperImpl#roleMapper
2021-03-09 07:41:56,228 INFO  [org.fly.cor.int.lic.VersionPrinter] (Quarkus Main Thread) Flyway Community Edition 7.5.2 by Redgate
2021-03-09 07:41:56,348 INFO  [org.fly.cor.int.dat.bas.DatabaseType] (Quarkus Main Thread) Database: jdbc:postgresql://localhost:5432/postgres (PostgreSQL 13.1)
2021-03-09 07:41:56,380 INFO  [org.fly.cor.int.com.DbClean] (Quarkus Main Thread) Successfully dropped pre-schema database level objects (execution time 00:00.001s)
2021-03-09 07:41:56,426 INFO  [org.fly.cor.int.com.DbClean] (Quarkus Main Thread) Successfully dropped schema "maripa" (execution time 00:00.044s)
2021-03-09 07:41:56,428 INFO  [org.fly.cor.int.com.DbClean] (Quarkus Main Thread) Successfully dropped schema " bicas" (execution time 00:00.001s)
2021-03-09 07:41:56,430 INFO  [org.fly.cor.int.com.DbClean] (Quarkus Main Thread) Successfully dropped schema " rhino" (execution time 00:00.001s)
2021-03-09 07:41:56,430 INFO  [org.fly.cor.int.com.DbClean] (Quarkus Main Thread) Successfully dropped post-schema database level objects (execution time 00:00.000s)
2021-03-09 07:41:56,432 INFO  [org.fly.cor.int.lic.VersionPrinter] (Quarkus Main Thread) Flyway Community Edition 7.5.2 by Redgate
2021-03-09 07:41:56,437 INFO  [org.fly.cor.int.dat.bas.Schema] (Quarkus Main Thread) Creating schema "maripa" ...
2021-03-09 07:41:56,439 INFO  [org.fly.cor.int.dat.bas.Schema] (Quarkus Main Thread) Creating schema " bicas" ...
2021-03-09 07:41:56,439 INFO  [org.fly.cor.int.dat.bas.Schema] (Quarkus Main Thread) Creating schema " rhino" ...
2021-03-09 07:41:56,443 INFO  [org.fly.cor.int.sch.JdbcTableSchemaHistory] (Quarkus Main Thread) Creating Schema History table "maripa"."flyway_schema_history" ...
2021-03-09 07:41:56,487 INFO  [org.fly.cor.int.com.DbMigrate] (Quarkus Main Thread) Current version of schema "maripa": null
2021-03-09 07:41:56,496 INFO  [org.fly.cor.int.com.DbMigrate] (Quarkus Main Thread) Migrating schema "maripa" to version "1.0.1 - start structure maripa"
2021-03-09 07:41:56,555 INFO  [org.fly.cor.int.com.DbMigrate] (Quarkus Main Thread) Successfully applied 1 migration to schema "maripa" (execution time 00:00.078
</code>```

my path scrpts

As you can see it ran only in the first schema. How to run on all three?

Obs.: Sorry by my english!  :)

答:
Late to this question but from the Quarkus docs it looks like this is by design.

The name of Flyway’s schema history table. By default (single-schema mode) the schema history table is placed in the default schema for the connection provided by the datasource. When the flyway.schemas property is set (multi-schema mode), the schema history table is placed in the first schema of the list.

I guess it only needs one schema table as all three 'tenants' should be kept to the same version?

Body:
Good morning, I'm trying to set up a QUARKUS project with flyway, hibernate, panache and multitenant.
But the script only runs once on the first schema, would anyone know how to run on the other schemas?

application.yml

 datasource:
   db-kind: postgres
   username: postgres
   password: 1234
   jdbc:
     url: jdbc:postgresql://localhost:5432/postgres
     driver: org.postgresql.Driver
 hibernate-orm:
   multitenant: SCHEMA
   dialect: org.hibernate.dialect.PostgreSQLDialect
   log:
     sql: true
 flyway:
   migrate-at-start: true
   baseline-on-migrate: true
   baseline-version: 1.0.0
   create-schemas: true
   clean-at-start: true
   schemas: maripa, bicas, rhino
   locations: db/migration/maripa, db/migration/bicas, db/migration/rhino

LOG

    __  ____  __  _____   ___  __ ____  ______
 --/ __ \/ / / / _ | / _ \/ //_/ / / / __/
 -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \
--\___\_\____/_/ |_/_/|_/_/|_|\____/___/
2021-03-09 07:41:54,213 INFO  [io.qua.fly.FlywayProcessor] (build-13) Adding application migrations in path '/home/idd_acosta/freelas/rhino/rhino-api/target/classes/db/migration/maripa/' using protocol 'file'
2021-03-09 07:41:54,844 INFO  [io.qua.arc.pro.BeanProcessor] (build-8) Found unrecommended usage of private members (use package-private instead) in application beans:
    - @Inject field br.com.rhino.user.mapper.RoleMapperImpl#permissionMapper,
    - @Inject field br.com.rhino.user.mapper.UserMapperImpl#roleMapper
2021-03-09 07:41:56,228 INFO  [org.fly.cor.int.lic.VersionPrinter] (Quarkus Main Thread) Flyway Community Edition 7.5.2 by Redgate
2021-03-09 07:41:56,348 INFO  [org.fly.cor.int.dat.bas.DatabaseType] (Quarkus Main Thread) Database: jdbc:postgresql://localhost:5432/postgres (PostgreSQL 13.1)
2021-03-09 07:41:56,380 INFO  [org.fly.cor.int.com.DbClean] (Quarkus Main Thread) Successfully dropped pre-schema database level objects (execution time 00:00.001s)
2021-03-09 07:41:56,426 INFO  [org.fly.cor.int.com.DbClean] (Quarkus Main Thread) Successfully dropped schema "maripa" (execution time 00:00.044s)
2021-03-09 07:41:56,428 INFO  [org.fly.cor.int.com.DbClean] (Quarkus Main Thread) Successfully dropped schema " bicas" (execution time 00:00.001s)
2021-03-09 07:41:56,430 INFO  [org.fly.cor.int.com.DbClean] (Quarkus Main Thread) Successfully dropped schema " rhino" (execution time 00:00.001s)
2021-03-09 07:41:56,430 INFO  [org.fly.cor.int.com.DbClean] (Quarkus Main Thread) Successfully dropped post-schema database level objects (execution time 00:00.000s)
2021-03-09 07:41:56,432 INFO  [org.fly.cor.int.lic.VersionPrinter] (Quarkus Main Thread) Flyway Community Edition 7.5.2 by Redgate
2021-03-09 07:41:56,437 INFO  [org.fly.cor.int.dat.bas.Schema] (Quarkus Main Thread) Creating schema "maripa" ...
2021-03-09 07:41:56,439 INFO  [org.fly.cor.int.dat.bas.Schema] (Quarkus Main Thread) Creating schema " bicas" ...
2021-03-09 07:41:56,439 INFO  [org.fly.cor.int.dat.bas.Schema] (Quarkus Main Thread) Creating schema " rhino" ...
2021-03-09 07:41:56,443 INFO  [org.fly.cor.int.sch.JdbcTableSchemaHistory] (Quarkus Main Thread) Creating Schema History table "maripa"."flyway_schema_history" ...
2021-03-09 07:41:56,487 INFO  [org.fly.cor.int.com.DbMigrate] (Quarkus Main Thread) Current version of schema "maripa": null
2021-03-09 07:41:56,496 INFO  [org.fly.cor.int.com.DbMigrate] (Quarkus Main Thread) Migrating schema "maripa" to version "1.0.1 - start structure maripa"
2021-03-09 07:41:56,555 INFO  [org.fly.cor.int.com.DbMigrate] (Quarkus Main Thread) Successfully applied 1 migration to schema "maripa" (execution time 00:00.078

my path scrpts

As you can see it ran only in the first schema. How to run on all three?

Obs.: Sorry by my english!  :)


问:
Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found
I am working on a fabric application where I have configured HTTPS. It is throwing an exception though I have a valid installed certificate.</p>

答:
If you are visiting this page and if you are unfortunate like me who tried every single solution/approach mentioned on this page but nothing worked, then you may like to know what I did and solved my problem.

I was getting this error from my ASP.NET Core web application no matter how many times I deleted the localhost certificates.

Then, I created a self-signed certificate using Powershell with this command. [I copied this PowerShell snippet from somewhere on the internet. Cannot remember the source.]
First, make sure that you have a writable location on your computer at C:\temp\. (You can use any other path as long as it can be read by your web app)

```<code>  $cert = New-SelfSignedCertificate -DnsName mydemowebapp.net -CertStoreLocation cert:\LocalMachine\My
  $pwd = ConvertTo-SecureString -String "MyPassword" -Force -AsPlainText
  Export-PfxCertificate -Cert $cert -FilePath C:\temp\cert.pfx -Password $pwd
</code>```

Then, in my appsertings.Development.json, I added this entry.

```<code>  "Kestrel": {
    "EndPoints": {
      "Https": {
        "Url": "https://localhost:5000",
        "Certificate": {
          "Path": "C:\\temp\\cert.pfx",
          "Password": "MyPassword",
          "AllowInvalid": "true"
        }
      }
    }
  }
</code>```

Ran the application, boom! problem solved. I used the same URL  https://localhost:5000 as I found in my LaunceSettings.

I hate a solution like this, but at least I could continue my development with such a solution. I do not know what really happened recently that I had to face this issue. Was that a windows update? or something else? I don't know. I did not face this issue before, until recently.
And yes, I remembered to run the Website in Kestrel rather than IIS.

Body:
If you are visiting this page and if you are unfortunate like me who tried every single solution/approach mentioned on this page but nothing worked, then you may like to know what I did and solved my problem.

I was getting this error from my ASP.NET Core web application no matter how many times I deleted the localhost certificates.

Then, I created a self-signed certificate using Powershell with this command. [I copied this PowerShell snippet from somewhere on the internet. Cannot remember the source.]
First, make sure that you have a writable location on your computer at C:\temp\. (You can use any other path as long as it can be read by your web app)

  $cert = New-SelfSignedCertificate -DnsName mydemowebapp.net -CertStoreLocation cert:\LocalMachine\My
  $pwd = ConvertTo-SecureString -String "MyPassword" -Force -AsPlainText
  Export-PfxCertificate -Cert $cert -FilePath C:\temp\cert.pfx -Password $pwd

Then, in my appsertings.Development.json, I added this entry.

  "Kestrel": {
    "EndPoints": {
      "Https": {
        "Url": "https://localhost:5000",
        "Certificate": {
          "Path": "C:\\temp\\cert.pfx",
          "Password": "MyPassword",
          "AllowInvalid": "true"
        }
      }
    }
  }

Ran the application, boom! problem solved. I used the same URL  https://localhost:5000 as I found in my LaunceSettings.

I hate a solution like this, but at least I could continue my development with such a solution. I do not know what really happened recently that I had to face this issue. Was that a windows update? or something else? I don't know. I did not face this issue before, until recently.
And yes, I remembered to run the Website in Kestrel rather than IIS.


问:
Unable to Write Out to PSObject an Array of Data pulled from DB2 database using IBM.Data.DB2 Connector
I'm able to extract the data to a CSV file directly when I use  $extractFile = 'D:\TEST\Q_sampler_result_file.csv' when I use Export-CSV to direct to $extractFile.

What is wrong  with how  I'm  using PSObject to bring this  same table  into an array which I would then, if successful direct to an HTML email?

```<code>Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS C:\Users\ME> $factory = [System.Data.Common.DbProviderFactories]::GetFactory("IBM.Data.DB2")
PS C:\Users\ME> $cstrbld = $factory.CreateConnectionStringBuilder()
PS C:\Users\ME> $cstrbld.Database = 'dbname'
PS C:\Users\ME> $cstrbld.UserID = 'ME'
PS C:\Users\ME> $cstrbld.Password = 'PWD'
PS C:\Users\ME> $cstrbld.Server = 'AIXbox:50001'
PS C:\Users\ME> $dbconn = $factory.CreateConnection()
PS C:\Users\ME> $dbconn.ConnectionString = $cstrbld.ConnectionString
PS C:\Users\ME> $dbconn.Open()
PS C:\Users\ME> $dbcmd = $factory.CreateCommand()
PS C:\Users\ME> $dbcmd.Connection = $dbconn
PS C:\Users\ME> ########################################################################################################################################
PS C:\Users\ME> #DEMONSTRATE --> showing count of how many failed work units in  Application.PFKIWORKUNIT
PS C:\Users\ME> $dbcmd.CommandText = 'SELECT PFIWORKUNIT,ACTOR,FLOWDEFINITION,WORKTITLE,STATUS FROM LAWSON.PFIWORKUNIT WHERE STATUS BETWEEN 0 AND 3'
PS C:\Users\ME> ########################################################################################################################################
PS C:\Users\ME> $dbcmd.CommandType = [System.Data.CommandType]::Text
PS C:\Users\ME> $da = $factory.CreateDataAdapter()
PS C:\Users\ME> $da.SelectCommand = $dbcmd
PS C:\Users\ME> $ds = New-Object System.Data.DataSet
PS C:\Users\ME> $rowCount = $da.Fill($ds)
PS C:\Users\ME> $dbconn.Close()
PS C:\Users\ME>
PS C:\Users\ME> write-host $rowCount
10 ##<-- There are TEN rows of data with the five columns named below
PS C:\Users\ME>
PS C:\Users\ME> if($rowCount -gt 0) {
>>
>>
>> $exportObject=@()
>> $Object = New-Object PSObject
>> $ds | ForEach{
>>         $Object | Add-Member -MemberType NoteProperty -Name "PFIWORKUNIT" -Value $row.PFIWORKUNIT
>>         $Object | Add-Member -MemberType NoteProperty -Name "ACTOR" -Value $row.ACTOR
>>         $Object | Add-Member -MemberType NoteProperty -Name "FLOWDEFINITION" -Value $row.FLOWDEFINITION
>>         $Object | Add-Member -MemberType NoteProperty -Name "WORKTITLE" -Value $row.WORKTITLE
>>         $Object | Add-Member -MemberType NoteProperty -Name "STATUS" -Value $row.STATUS
>>         $exportObject += $Object
>> }
>>
>>
>> write-host $exportObject
>> }
>>
@{PFIWORKUNIT=; ACTOR=; FLOWDEFINITION=; WORKTITLE=; STATUS=} ##<-- listing out ONLY Headers of Columns

</code>```

答:
The problem is your use of $row within the ForEach loop. In the context that you are using ForEach it is actually short for ForEach-Object. When it iterates through an array each iteration is represented by $_, but that representation is lost by the time that you want to reference it because you're piping $Object to something, so at that point when you reference $row, the $_ value would refer to $Object.

What you may want to try is ForEach($row in $ds){. That will iterate through $ds, and for each item in the array that item will be represented by $row. Though, with $ds being a dataset, wouldn't you want $ds.tables[0].rows? Something like:

```<code>$exportObjects = ForEach($row in $ds.tables[0].rows){
    [pscustomobject]@{
         "PFIWORKUNIT" = $row.PFIWORKUNIT
         "ACTOR" = $row.ACTOR
         "FLOWDEFINITION" = $row.FLOWDEFINITION
         "WORKTITLE" = $row.WORKTITLE
         "STATUS" = $row.STATUS
    }
}
</code>```

I'm pretty sure that will end up with $exportObjects being the array that you want to be able to convert to HTML. It also avoids the += you were doing before, which is a costly PowerShell process because it destroys and recreates the referencing array each time it happens. Instead I just make objects in the loop, and collect them all in a variable at once.

Body:
I'm able to extract the data to a CSV file directly when I use  $extractFile = 'D:\TEST\Q_sampler_result_file.csv' when I use Export-CSV to direct to $extractFile.

What is wrong  with how  I'm  using PSObject to bring this  same table  into an array which I would then, if successful direct to an HTML email?

Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS C:\Users\ME> $factory = [System.Data.Common.DbProviderFactories]::GetFactory("IBM.Data.DB2")
PS C:\Users\ME> $cstrbld = $factory.CreateConnectionStringBuilder()
PS C:\Users\ME> $cstrbld.Database = 'dbname'
PS C:\Users\ME> $cstrbld.UserID = 'ME'
PS C:\Users\ME> $cstrbld.Password = 'PWD'
PS C:\Users\ME> $cstrbld.Server = 'AIXbox:50001'
PS C:\Users\ME> $dbconn = $factory.CreateConnection()
PS C:\Users\ME> $dbconn.ConnectionString = $cstrbld.ConnectionString
PS C:\Users\ME> $dbconn.Open()
PS C:\Users\ME> $dbcmd = $factory.CreateCommand()
PS C:\Users\ME> $dbcmd.Connection = $dbconn
PS C:\Users\ME> ########################################################################################################################################
PS C:\Users\ME> #DEMONSTRATE --> showing count of how many failed work units in  Application.PFKIWORKUNIT
PS C:\Users\ME> $dbcmd.CommandText = 'SELECT PFIWORKUNIT,ACTOR,FLOWDEFINITION,WORKTITLE,STATUS FROM LAWSON.PFIWORKUNIT WHERE STATUS BETWEEN 0 AND 3'
PS C:\Users\ME> ########################################################################################################################################
PS C:\Users\ME> $dbcmd.CommandType = [System.Data.CommandType]::Text
PS C:\Users\ME> $da = $factory.CreateDataAdapter()
PS C:\Users\ME> $da.SelectCommand = $dbcmd
PS C:\Users\ME> $ds = New-Object System.Data.DataSet
PS C:\Users\ME> $rowCount = $da.Fill($ds)
PS C:\Users\ME> $dbconn.Close()
PS C:\Users\ME>
PS C:\Users\ME> write-host $rowCount
10 ##<-- There are TEN rows of data with the five columns named below
PS C:\Users\ME>
PS C:\Users\ME> if($rowCount -gt 0) {
>>
>>
>> $exportObject=@()
>> $Object = New-Object PSObject
>> $ds | ForEach{
>>         $Object | Add-Member -MemberType NoteProperty -Name "PFIWORKUNIT" -Value $row.PFIWORKUNIT
>>         $Object | Add-Member -MemberType NoteProperty -Name "ACTOR" -Value $row.ACTOR
>>         $Object | Add-Member -MemberType NoteProperty -Name "FLOWDEFINITION" -Value $row.FLOWDEFINITION
>>         $Object | Add-Member -MemberType NoteProperty -Name "WORKTITLE" -Value $row.WORKTITLE
>>         $Object | Add-Member -MemberType NoteProperty -Name "STATUS" -Value $row.STATUS
>>         $exportObject += $Object
>> }
>>
>>
>> write-host $exportObject
>> }
>>
@{PFIWORKUNIT=; ACTOR=; FLOWDEFINITION=; WORKTITLE=; STATUS=} ##<-- listing out ONLY Headers of Columns

Body:
The problem is your use of $row within the ForEach loop. In the context that you are using ForEach it is actually short for ForEach-Object. When it iterates through an array each iteration is represented by $_, but that representation is lost by the time that you want to reference it because you're piping $Object to something, so at that point when you reference $row, the $_ value would refer to $Object.

What you may want to try is ForEach($row in $ds){. That will iterate through $ds, and for each item in the array that item will be represented by $row. Though, with $ds being a dataset, wouldn't you want $ds.tables[0].rows? Something like:

$exportObjects = ForEach($row in $ds.tables[0].rows){
    [pscustomobject]@{
         "PFIWORKUNIT" = $row.PFIWORKUNIT
         "ACTOR" = $row.ACTOR
         "FLOWDEFINITION" = $row.FLOWDEFINITION
         "WORKTITLE" = $row.WORKTITLE
         "STATUS" = $row.STATUS
    }
}

I'm pretty sure that will end up with $exportObjects being the array that you want to be able to convert to HTML. It also avoids the += you were doing before, which is a costly PowerShell process because it destroys and recreates the referencing array each time it happens. Instead I just make objects in the loop, and collect them all in a variable at once.


问:
Nested async methods... do I need to await?
Let's say I have an existing async method returning a Task that runs well. It awaits and is itself awaited properly. This method takes an int argument:

```<code>public async Task<MyType> MyMethod(int foo)
{
    // .. do stuff
}
</code>```

We want to update this method to instead accept a string, and if we can parse an int from the string, then do what we've always done (moved to a new helper method), otherwise, if we can parse a Guid, then a call a different (but very similar) method. If neither type will parse, then return an empty/noop result:

```<code>public async Task<MyType> MyMethod(string foo)
{
    if ( int.TryParse(foo, out int bar))
    {
        return MyIntHelper(bar);
    }
    else if (Guid.TryParse(foo, out Guid bar))
    {
        return MyGuidHelper(bar);
    }
    else return MyNoop();
}

private async Task<MyType> MyIntHelper(int foo)
{
    // original ".. do stuff" here
}

private async Task<MyType> MyGuidHelper(Guid foo)
{
    // similar ".. do stuff" here, but using a Guid instead
}
</code>```

The question is, in the updated MyMethod(), do I need to await the results of the helper methods, or since I'm already returning a Task and any necessary awaiting is still in the caller and child methods am I already covered?

As some background, this is in the context of updating a controller to accept an additional "endpoint", but really I'd like to decouple the question from that context as much as possible.

答:
in the updated MyMethod(), do I need to await the results of the helper methods

If you use async, then you should use await. As a general rule, you should use async and await for most asynchronous methods.

Anytime you have nontrivial logic (including the possibility of exceptions), you should use async and await. For trivial method implementations, you can elide async and await (as described on my blog).

Body:
Let's say I have an existing async method returning a Task that runs well. It awaits and is itself awaited properly. This method takes an int argument:

public async Task<MyType> MyMethod(int foo)
{
    // .. do stuff
}

We want to update this method to instead accept a string, and if we can parse an int from the string, then do what we've always done (moved to a new helper method), otherwise, if we can parse a Guid, then a call a different (but very similar) method. If neither type will parse, then return an empty/noop result:

public async Task<MyType> MyMethod(string foo)
{
    if ( int.TryParse(foo, out int bar))
    {
        return MyIntHelper(bar);
    }
    else if (Guid.TryParse(foo, out Guid bar))
    {
        return MyGuidHelper(bar);
    }
    else return MyNoop();
}

private async Task<MyType> MyIntHelper(int foo)
{
    // original ".. do stuff" here
}

private async Task<MyType> MyGuidHelper(Guid foo)
{
    // similar ".. do stuff" here, but using a Guid instead
}

The question is, in the updated MyMethod(), do I need to await the results of the helper methods, or since I'm already returning a Task and any necessary awaiting is still in the caller and child methods am I already covered?

As some background, this is in the context of updating a controller to accept an additional "endpoint", but really I'd like to decouple the question from that context as much as possible.


问:
Is there a way to leave an argument out of the help using python argparse
I have an argument that is an internal debug flag and shouldn't be run by users who don't know what they are doing.
I realize that hiding it is in essence security by obscurity, but I'm not concerned about malice so much as incompetence.
Optparse had a SUPPRESS_HELP option, is there and argparse equivalent?</p>

答:
```<code>parser.add_argument('--secret', help=argparse.SUPPRESS)
</code>```

From here: http://argparse.googlecode.com/svn/trunk/doc/argparse-vs-optparse.html

First Google result for argparse suppress_help, by the way.

ContentLicense: CC BY-SA 3.0

Body:
parser.add_argument('--secret', help=argparse.SUPPRESS)

From here: http://argparse.googlecode.com/svn/trunk/doc/argparse-vs-optparse.html

First Google result for argparse suppress_help, by the way.


问:
How do filter with multiple contains in pyspark
I'm going to do a query with pyspark to filter row who contains at least one word in array. For example, the dataframe is:

```<code>     "content"                "other"
My father is big.              ...
My mother is beautiful.        ...
I'm going to travel.           ...
</code>```

I have an array:

```<code>array=["mother","father"]
</code>```

And the output must be this:

```<code>     "content"                "other"
My father is big.              ...
My mother is beautiful.        ...
</code>```

A simple filter for word in array.

答:
I think this solution works. Let me know what you think.

```<code>import pyspark.sql.functions as f
phrases = ['bc', 'ij']

df = spark.createDataFrame([
  ('abcd',),
  ('efgh',),
  ('ijkl',)
], ['col1'])

(df
 .withColumn('phrases', f.array([f.lit(element) for element in phrases]))
 .where(f.expr('exists(phrases, element -> col1 like concat("%", element, "%"))'))
 .drop('phrases')
 .show()
)
</code>```

output

```<code>+----+
|col1|
+----+
|abcd|
|ijkl|
+----+
</code>```

Body:
I'm going to do a query with pyspark to filter row who contains at least one word in array. For example, the dataframe is:

     "content"                "other"
My father is big.              ...
My mother is beautiful.        ...
I'm going to travel.           ...

I have an array:

array=["mother","father"]

And the output must be this:

     "content"                "other"
My father is big.              ...
My mother is beautiful.        ...

A simple filter for word in array.

Body:
I think this solution works. Let me know what you think.

import pyspark.sql.functions as f
phrases = ['bc', 'ij']

df = spark.createDataFrame([
  ('abcd',),
  ('efgh',),
  ('ijkl',)
], ['col1'])

(df
 .withColumn('phrases', f.array([f.lit(element) for element in phrases]))
 .where(f.expr('exists(phrases, element -> col1 like concat("%", element, "%"))'))
 .drop('phrases')
 .show()
)

output

+----+
|col1|
+----+
|abcd|
|ijkl|
+----+