<commit_before>package com.gu.scanamo

import com.amazonaws.auth.{AWSStaticCredentialsProvider, BasicAWSCredentials}
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration
import com.amazonaws.services.dynamodbv2._
import com.amazonaws.services.dynamodbv2.model._

import scala.collection.JavaConverters._

object LocalDynamoDB {
  def client(): AmazonDynamoDBAsync =
    AmazonDynamoDBAsyncClient
      .asyncBuilder()
      .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("dummy", "credentials")))
      .withEndpointConfiguration(new EndpointConfiguration("http://localhost:8042", ""))
      .build()

  def createTable(client: AmazonDynamoDB)(tableName: String)(attributes: (Symbol, ScalarAttributeType)*) = {
    var created = false
    while (!created) {
      try {
        client.createTable(
          attributeDefinitions(attributes),
          tableName,
          keySchema(attributes),
          arbitraryThroughputThatIsIgnoredByDynamoDBLocal
        )
        created = true
      } catch {
        case _ => client.deleteTable(tableName)          
      }
    }
  }
<commit_msg>Check preexisting table exception<commit_after>package com.gu.scanamo

import com.amazonaws.auth.{AWSStaticCredentialsProvider, BasicAWSCredentials}
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration
import com.amazonaws.services.dynamodbv2._
import com.amazonaws.services.dynamodbv2.model._

import scala.collection.JavaConverters._

object LocalDynamoDB {
  def client(): AmazonDynamoDBAsync =
    AmazonDynamoDBAsyncClient
      .asyncBuilder()
      .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("dummy", "credentials")))
      .withEndpointConfiguration(new EndpointConfiguration("http://localhost:8042", ""))
      .build()

  def createTable(client: AmazonDynamoDB)(tableName: String)(attributes: (Symbol, ScalarAttributeType)*) = {
    var created = false
    while (!created) {
      try {
        client.createTable(
          attributeDefinitions(attributes),
          tableName,
          keySchema(attributes),
          arbitraryThroughputThatIsIgnoredByDynamoDBLocal
        )
        created = true
      } catch {
        case x: ResourceInUseException if x.getMessage.contains("preexisting") => client.deleteTable(tableName)
      }
    }
  }

{'fraction_non_alphanumeric': 0.09388275276125743, 'fraction_numerical': 0.005097706032285472, 'mean_word_length': 3.796334012219959, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1214991', 'n_tokens_mistral': 661, 'n_tokens_neox': 663, 'n_words': 105}