Iex.new

Iex.new

Hi,

in our Team at work we have Hackathons and for next year I am thinking about to introduce Elixir. As we have todo with data processing in our daily work I planning to propose a small app that should import data in parallel from a huge csv file (let say for example a list of persons) into a database. And maybe to transform the data in between.
I think I would also like to show the results in the front end using Pheonix.

During my research I came across Flow and Broadway.
As I have not so much experience with Elixir and never used Flow/Broadway, what could be a good fit for my experimentation ?

I find this article on dev.to which seems to close to what I want to do :

Thank you!

Showing Posts 47 to 38

Iex.new

Iex.new OP

Looks like you don’t have a detection of duplicates so you’re constantly inserting the same records.

Your next step is to add an unique index on the name (or another field) to make sure you don’t duplicate so much.

Yes I will do that!

And it would have been useful for you to mention your exact steps before. We’re not mind readers. :smiley:

I will take care of that for my future posts :slight_smile: Sorry about that!

I consider this thread completed. Mark one of my answers as the solution (if you don’t mind) and if you have other problems, they are for a new thread IMO.

I already did it :slight_smile:

Thank you all of you for your support!

dimitarvp

dimitarvp

Looks like you don’t have a detection of duplicates so you’re constantly inserting the same records.

Your next step is to add an unique index on the name (or another field) to make sure you don’t duplicate so much.

And it would have been useful for you to mention your exact steps before. We’re not mind readers. :smiley:

I consider this thread completed. Mark one of my answers as the solution (if you don’t mind) and if you have other problems, they are for a new thread IMO.

Iex.new

Iex.new OP

Thank you for giving me the command you use to load the file. After using the same command I can confirm that I came to the same result as you, It works!

That’s confirm my doubt in my previous comment :

Maybe the file_watcher.ex is not properly configured (and the CSV file is endlessly loaded?)?

How I proceed to run in this error:

  1. mix deps.get (if I run the app for the first time)
  2. docker-compose up --build
  3. docker exec -ti file_watch_example_new_elixir_app_1 bash
    2.1 mix ecto.drop
    2.1 mix ecto.create
    2.1 mix ecto.migrate
  4. outside the container: cp products.csv data/in

In the Elixir App, I have a “file watcher” that should check for new incoming files in the directory data/in. If a new file is detected, then it should be loaded by IngestCSV (see line #20. So I think this process is wrong defined/configured and seems infinite load the CSV-File…

dimitarvp

dimitarvp

Man, this is getting tiring. Just drop the DB, create it again, run the migration, and then start the code.

And indeed as @D4no0 said, post some command output e.g. mysql -e 'select count(id) from products;' before and after.

The code I did is working perfectly, you are missing something else and I believe it’s time you get a grip and make it work. :wink:

Are you opening iex -S mix and then running IngestCSV.load("10_million_products.csv")? Is there any other code you’re not showing?

D4no0

D4no0

Command ecto.migrate does not delete old data, it runs the migrations otherwise if everything is up-to-date it does nothing.

In your case you want to delete the entire database before inserting new data. This can be done by explicitly running ecto.reset, or ecto.drop followed by ecto.create and ecto.migrate.

To have easier visibility on what happens in your database I would strongly recommend using a cli tool to query it, or even better a visual tool like dbeaver.

Iex.new

Iex.new OP

@dimitarvp, I have merged your modifications and then cloned the repo into a new local directory.
Afterward, I run the Ecto-migration with mix ecto.migrate (so at that moment the table products is empty)
When the migration was finished I copied the CSV file into data/in.
I am very surprised at how fast the records are created in the database! :slight_smile:

mysql> select count(*) from products;
+----------+
| count(*) |
+----------+
| 84040000 |
+----------+

As you can see the number I got is much higher than the number of rows the file contains:

 cat products.csv | wc -l
10000000

Maybe the file_watcher.ex is not properly configured (and the CSV file is endlessly loaded?)?

dimitarvp

dimitarvp

You are sorted. Here is the PR: Make it work by dimitarvp · Pull Request #1 · pascal-chenevas/file_watch_example · GitHub

I made it use batch inserting again and it works just fine. Only takes 108 seconds on my Intel Mac to insert exactly 10 million records.

Try my branch on your machine and let us know. No reason not to work unless your MySQL instance is broken, or you are not showing all your code and something else in it is bugging it.

dimitarvp

dimitarvp

You have a mistake in your data sample file. First line contains a shell prompt:

anonymized@ANONYMIZED:~/file_watch_example$ head -100

The rest is valid CSV.

dimitarvp

dimitarvp

Dude, you have no database migration to create the table. Put one in! How can anyone help you if you haven’t took care to create the DB schema?

EDIT: I mean, it’s pretty simple, you should have included it:

defmodule Store.Migrations.AddProducts do
  use Ecto.Migration

  def change do
    create table(:products) do
      add(:name, :string)
      add(:bar_code, :string)
      add(:price, :string)
      add(:currency, :string)
      timestamps(type: :utc_datetime_usec)
    end
  end
end
dimitarvp

dimitarvp

What MySQL engine are you using? Is it MariaDB or good old MySQL version? And what version?

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews