<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Is there a better way for this  matching? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/is-there-a-better-way-for-this-matching/m-p/23232#M15997</link>
    <description>&lt;P&gt;I have an array:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;var arg = condColumnsKeys&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;with the elements&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;arg: Array[String] = Array(LOT_PREFIX, PS_NAME_BOOK_TEMPLATE_NAME, PS_NAME_PAGE_NAME, PS_NAME_FIELD_NAME)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Desired outcome is to get the string "LOT_PREFIX" and store it in var ccLotPrefix&lt;/P&gt;&lt;P&gt;My first attempt is&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;var arg = condColumnsKeys
var ccLotPrefix =
  arg match {
   case "L_PREFIX" =&amp;gt; "L_PREFIX"
   case "LOT_PREFIX" =&amp;gt; "LOT_PREFIX"
   case _=&amp;gt; "LOT_PREFIX"
 }&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But I get a type mismatch as it needs to match with &lt;I&gt;Array[String]&lt;/I&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;command-4310537:4: error: type mismatch;
 found   : String("L_PREFIX")
 required: Array[String]
   case "L_PREFIX" =&amp;gt; "L_PREFIX"
        ^&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So my idea is to pack it into a for loop?&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;var j = (r.findAllIn(condValues).count(_ == "!"))
var arg = condColumnsKeys
for(j&amp;lt;-(0).to(j)) {
  var ccLotPrefix =
  arg match {
   case "L_PREFIX" =&amp;gt; "L_PREFIX"
   case "LOT_PREFIX" =&amp;gt; "LOT_PREFIX"
   case _=&amp;gt; "LOT_PREFIX"
 }
}&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But I still don't get rid of the type mismatch. So, after some trial/error this can be achieved by&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;for(i&amp;lt;-(0).to(i)) {
  if (arg(i) == "LOT_PREFIX")
   ccLotPrefix = "LOT_PREFIX"
  else if (arg(i) == "L_PREFIX")
   ccLotPrefix = "L_PREFIX"
}
println(ccLotPrefix)&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;LOT_PREFIX&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But is there a better way to achieve this? Because, obviously, you don't always know what's inside the array....&lt;/P&gt;</description>
    <pubDate>Fri, 08 Apr 2022 17:57:23 GMT</pubDate>
    <dc:creator>TS</dc:creator>
    <dc:date>2022-04-08T17:57:23Z</dc:date>
    <item>
      <title>Is there a better way for this  matching?</title>
      <link>https://community.databricks.com/t5/data-engineering/is-there-a-better-way-for-this-matching/m-p/23232#M15997</link>
      <description>&lt;P&gt;I have an array:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;var arg = condColumnsKeys&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;with the elements&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;arg: Array[String] = Array(LOT_PREFIX, PS_NAME_BOOK_TEMPLATE_NAME, PS_NAME_PAGE_NAME, PS_NAME_FIELD_NAME)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Desired outcome is to get the string "LOT_PREFIX" and store it in var ccLotPrefix&lt;/P&gt;&lt;P&gt;My first attempt is&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;var arg = condColumnsKeys
var ccLotPrefix =
  arg match {
   case "L_PREFIX" =&amp;gt; "L_PREFIX"
   case "LOT_PREFIX" =&amp;gt; "LOT_PREFIX"
   case _=&amp;gt; "LOT_PREFIX"
 }&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But I get a type mismatch as it needs to match with &lt;I&gt;Array[String]&lt;/I&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;command-4310537:4: error: type mismatch;
 found   : String("L_PREFIX")
 required: Array[String]
   case "L_PREFIX" =&amp;gt; "L_PREFIX"
        ^&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So my idea is to pack it into a for loop?&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;var j = (r.findAllIn(condValues).count(_ == "!"))
var arg = condColumnsKeys
for(j&amp;lt;-(0).to(j)) {
  var ccLotPrefix =
  arg match {
   case "L_PREFIX" =&amp;gt; "L_PREFIX"
   case "LOT_PREFIX" =&amp;gt; "LOT_PREFIX"
   case _=&amp;gt; "LOT_PREFIX"
 }
}&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But I still don't get rid of the type mismatch. So, after some trial/error this can be achieved by&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;for(i&amp;lt;-(0).to(i)) {
  if (arg(i) == "LOT_PREFIX")
   ccLotPrefix = "LOT_PREFIX"
  else if (arg(i) == "L_PREFIX")
   ccLotPrefix = "L_PREFIX"
}
println(ccLotPrefix)&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;LOT_PREFIX&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But is there a better way to achieve this? Because, obviously, you don't always know what's inside the array....&lt;/P&gt;</description>
      <pubDate>Fri, 08 Apr 2022 17:57:23 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/is-there-a-better-way-for-this-matching/m-p/23232#M15997</guid>
      <dc:creator>TS</dc:creator>
      <dc:date>2022-04-08T17:57:23Z</dc:date>
    </item>
  </channel>
</rss>

