<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Blog Azure Data Platform, BI &amp; EPM</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/franmer/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/franmer/feed.xml</link>
    <description>Blog en français traitant des sujets fonctionnels et techniques autour des solutions Azure Data Platform, BI &amp;amp; EPM</description>
    <lastBuildDate>Tue, 16 Apr 2019 06:07:17 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>SQL Server 2008 end of support</title>
      <link>https://docs.microsoft.com/archive/blogs/franmer/sql-server-2008-end-of-support-2</link>
      <pubDate>Thu, 01 Nov 2018 14:12:30 GMT</pubDate>
      <dc:creator><![CDATA[Franck Mercier]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/franmer/?p=13735</guid>
      <description><![CDATA[July 9, 2019 will be the end of support for the 2008 and 2008 R2 versions of SQL Server. There is...]]></description>
      <content:encoded><![CDATA[<p><span style="color:#212121;font-family:Arial;font-size:12pt">July 9, 2019 will be the end of support for the 2008 and 2008 R2 versions of SQL Server. There is still time to migrate your servers to the new SQL Server version. And why not take the opportunity to migrate to Azure. And try new Azure service, SQL Managed Instance (MI), now available in "GA" since October 2018, and allows a near 100% compatibility with a SQL Server installed on-premise.
</span></p><p><span style="color:#212121;font-family:Arial;font-size:12pt">Finally, in the case of applications that cannot be migrated in the coming months, there is the possibility of hosting them in Azure virtual machines, by using SQL Server template, and to benefit for an additional support extension.
</span></p><p><span style="color:#212121;font-family:Arial;font-size:12pt">In this article, we will see, depending on the situation, what are the options to continue using your applications in the best conditions of support and features.
</span></p><p>
 </p><p>Below, here are the 4 migration possibilities:
</p><ul><li>On-premise migration to the 2017 version (When possible for your applications)
</li><li>Migration to SQL Database (PaaS) (When possible for your applications)
</li><li>Migration to Azure SQL Database Managed Instance, which offers nearly 100% SQL Server compatibility
</li><li>For applications that are difficult to migrate in the coming months, deploying to an Azure VM with SQL server pre-installed (via virtual machine template)
</li></ul><p>
 </p><h1>Prerequisites
</h1><p><span style="color:#212121;font-family:Arial">In general, the migration process looks like the steps illustrated below. Even if in the end, there are many ways to execute a migration plan, it remains a project in its own:</span>
	</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/11/110118_1412_SQLServer201.png" alt="" />
	</p><p>The discovery part can be realized with MAP Toolkit:
</p><p><a href="https://docs.microsoft.com/en-us/previous-versions//bb977556(v=technet.10)">https://docs.microsoft.com/en-us/previous-versions//bb977556(v=technet.10)</a>
	</p><p><span style="color:#212121;font-family:Arial">However, whatever the solution considered, it is a good idea to perform the following tasks before any migration:
</span></p><p>
 </p><p>
 </p><p>On SQL Server 2008 or 2008 R2:
</p><ul><li>Check that the last service pack is correctly installed
</li><li>Rebuild indexes (if the indexes are very fragmented)
</li><li>Check the integrity of your database with <a href="https://docs.microsoft.com/en-us/sql/t-sql/database-console-commands/dbcc-checkdb-transact-sql?view=sql-server-2017"><span style="font-family:Arial;font-size:12pt">DBCC CHECKDB ()</span></a> (or on a copy, as this can take a long time)
</li><li>Note if the database is not linked to a maintenance plan
</li><li>Note if linked servers exist
</li><li>Note if the SQL Agent is used
</li><li>Do a full backup
</li></ul><p>
 </p><p><pre><code><span style="color:#212121;font-family:Arial;font-size:12pt">On a target:
</span></code></pre></p><p>
 </p><ul><li>After restoring your database, check again the integrity of your database with DBCC CHECKDB:
</li><li>DBCC_CHECKDB  WITH DATA_PURITY: <a href="https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Ft-sql%2Fdatabase-console-commands%2Fdbcc-checkdb-transact-sql%3Fview%3Dsql-server-2017&amp;data=02%7C01%7Cfranmer%40microsoft.com%7Cba4f677f00bb433b0bb508d63f5b3ef3%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636766058456449823&amp;sdata=GOhWbe7x8cVui4cUfZK5OXLMv6MTf3SnvncUCzUDO2U%3D&amp;reserved=0">https://docs.microsoft.com/en-us/sql/t-sql/database-console-commands/dbcc-checkdb-transact-sql?view=sql-server-2017</a>
		</li><li>Do a DBCC UPDATEUSAGE (<a href="https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Ft-sql%2Fdatabase-console-commands%2Fdbcc-updateusage-transact-sql%3Fview%3Dsql-server-2017&amp;data=02%7C01%7Cfranmer%40microsoft.com%7Cba4f677f00bb433b0bb508d63f5b3ef3%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636766058456459832&amp;sdata=Y7j6eMma7oMRj%2BRxtnE%2BBx8HXcgZeDA9E91JKKqODRY%3D&amp;reserved=0">https://docs.microsoft.com/en-us/sql/t-sql/database-console-commands/dbcc-updateusage-transact-sql?view=sql-server-2017</a>) 
</li><li><span style="font-size:12pt">Update statistics
</span></li><li><span style="font-size:12pt">Rebuild indexes
</span></li><li><div><span style="font-size:12pt">Check the compatibility mode (be very careful, the database will use the new Cardinality Estimator introduced with SQL 2014)
</span></div><p>
 </p></li></ul><h1>Migrate to SQL Server 2017 (On-premise)
</h1><p>Here we are in a classic migration scenario. With SQL Server 2017, it is possible to either go through a backup and then restore the database or use the data Migration Assistant (DMA) tool. 
</p><p>In addition to the prerequisites detailed earlier in this article, on the target server that hosts SQL server 2017, check the following points:
</p><ul><li>Use a supported operating system: <a href="https://docs.microsoft.com/en-us/sql/sql-server/install/hardware-and-software-requirements-for-installing-sql-server?view=sql-server-2017">https://docs.microsoft.com/en-us/sql/sql-server/install/hardware-and-software-requirements-for-installing-sql-server?view=sql-server-2017</a>
		</li><li>Check the space of the different disks (TempDB, Logs, Data)
</li><li>Recreate maintenance plans, linked servers and other SQL agents if necessary
</li></ul><p>Finally, also check the deprecated features in the SQL Server version 2017:
</p><p><a href="https://docs.microsoft.com/en-us/sql/database-engine/deprecated-database-engine-features-in-sql-server-2017?view=sql-server-2017">https://docs.microsoft.com/en-us/sql/database-engine/deprecated-database-engine-features-in-sql-server-2017?view=sql-server-2017</a>
	</p><p>
 </p><p>For the migration itself, the following methods can be used: 
</p><h3>database backup and restore
</h3><ul><li>Since version 2017, it is possible to create a database since the backup of a database in version 2005 or higher. Detailed documentation of this feature is available on this Web page: <a href="https://docs.microsoft.com/en-us/sql/relational-databases/databases/copy-databases-with-backup-and-restore?view=sql-server-2017">https://docs.microsoft.com/en-us/sql/relational-databases/databases/copy-databases-with-backup-and-restore?view=sql-server-2017</a>
		</li></ul><p>
 </p><h3>Data Migration Assistant
</h3><ul><li><div>Data Migration Assistant (DMA) is a <a href="https://www.microsoft.com/en-us/download/details.aspx?id=53595">downloadable tool</a>, which will be used to:
</div><ul><li><strong>Do an assessment</strong> of your databases to migrate, in order to evaluate the Migration effort. A complete documentation can be found on this web page: <a href="https://docs.microsoft.com/en-us/sql/dma/dma-assesssqlonprem?view=sql-server-2017">https://docs.microsoft.com/en-us/sql/dma/dma-assesssqlonprem?view=sql-server-2017</a>
				</li><li><strong>Do the migration</strong>. DMA can do the migration automatically. A complete documentation of the migration process is available here: <a href="https://docs.microsoft.com/en-us/sql/dma/dma-migrateonpremsql?view=sql-server-2017">https://docs.microsoft.com/en-us/sql/dma/dma-migrateonpremsql?view=sql-server-2017</a>
				</li></ul></li></ul><p>
 </p><p>
 </p><h1>Migrate to SQL Database (PaaS)
</h1><p>This is another possibility of migration, and the opportunity to modernize your data infrastructure with Cloud solutions. In addition, you will benefit from all the advantages of a managed service (no hardware management, 3 copies of your data, transparent updates, elasticity, …).
</p><p>Again, there are several ways to migrate your SQL Server databases to SQL database. But mainly, the 3 methods illustrated below can be used, after consulting the detailed prerequisites above. Of course, double check the prerequisites section as a first step:
</p><p style="text-align: center"><img src="https://msdnshared.blob.core.windows.net/media/2018/11/110118_1412_SQLServer202.png" alt="" />
	</p><ul><li>Transactional Replication: <a href="https://docs.microsoft.com/en-us/azure/sql-database/sql-database-cloud-migrate#method-2-use-transactional-replication">https://docs.microsoft.com/en-us/azure/sql-database/sql-database-cloud-migrate#method-2-use-transactional-replication</a>
		</li><li>Import / Export BACPAC File: <a href="https://docs.microsoft.com/en-us/azure/sql-database/sql-database-import">https://docs.microsoft.com/en-us/azure/sql-database/sql-database-import</a>
		</li><li> Use <a href="https://docs.microsoft.com/en-us/azure/sql-database/sql-database-migrate-your-sql-server-database">DMA tool</a>. Be careful, this operation will make your database inaccessible during the migration process!
</li></ul><p>In order to measure the impact of migration, it is possible to use the Database experimentation Assistant (DEA) tool. This tool allows you to capture traces, on an existing server, to be replayed on SQL Database, SQL managed instance or SQL on Linux. DEA can be downloaded here: <a href="https://www.microsoft.com/en-us/download/details.aspx?id=54090">https://www.microsoft.com/en-us/download/details.aspx?id=54090</a>
	</p><p>
 </p><p>Finally, as I mentioned earlier, there are other possible ways to migrate its databases such as using SQL Server integration Services (SSIS) or Azure Data Factory v2.  
</p><p>
 </p><p> </p><h1>Migrate to Azure SQL Database Managed Instance (PaaS)
</h1><p>SQL database Managed Instance (MI) is a managed service (PaaS) that provides SQL Server compatibility close to 100%, while supporting features that are not present in SQL database such as:
</p><ul style="margin-left: 54pt"><li>Native backup/restore function
</li><li>Linked Server
</li><li>CLR
</li><li>SQL Agent
</li><li>DB Mail (external SMTP)
</li><li>...
</li></ul><p>In addition, SQL database MI works in its own VNet, which helps to enhance the security of your database.... But at the expense, today, of a lack of integration with, for example, other Azure services.
</p><p>
 </p><p>A complete SQL database MI overview is available on this Web page: <a href="https://docs.microsoft.com/en-us/azure/sql-database/sql-database-managed-instance#sql-features-supported">https://docs.microsoft.com/en-us/azure/sql-database/sql-database-managed-instance#sql-features-supported</a>
	</p><p>Again, after double check migration prerequisites, several ways are possible to migrate to SQL Database MI:
</p><ul><li>Azure Database Migration Service (which will use DMA for the assessment part of the migration effort) : <a href="https://docs.microsoft.com/en-us/azure/dms/dms-overview">https://docs.microsoft.com/en-us/azure/dms/dms-overview</a>
		</li><li>Native Restore from a URL. I explained in an article, which dates a little <span style="font-family:Segoe UI Emoji">😊</span>, how to do this type of backup (article in French): <a href="https://blogs.technet.microsoft.com/franmer/2013/11/15/sql-server-2014-intgration-avec-le-stockage-azure/">https://blogs.technet.microsoft.com/franmer/2013/11/15/sql-server-2014-intgration-avec-le-stockage-azure/</a>. But this article is more up to date: <a href="https://docs.microsoft.com/en-us/sql/relational-databases/backup-restore/sql-server-backup-to-url?view=sql-server-2017">https://docs.microsoft.com/en-us/sql/relational-databases/backup-restore/sql-server-backup-to-url?view=sql-server-2017</a>
		</li></ul><p>Overall the backup from a URL will follow the following path:
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/11/110118_1412_SQLServer203.png" alt="" />
	</p><p>More details for all migration path are available here: 
</p><p><a href="https://docs.microsoft.com/en-us/azure/sql-database/sql-database-managed-instance-migrate">https://docs.microsoft.com/en-us/azure/sql-database/sql-database-managed-instance-migrate</a>
	</p><p>Pay attention to the following points:
</p><ul><li>SQL Database Managed Instance must be deployed within a virtual network. The following article gives the configuration details: <a href="https://docs.microsoft.com/en-us/azure/sql-database/sql-database-managed-instance-vnet-configuration">https://docs.microsoft.com/en-us/azure/sql-database/sql-database-managed-instance-vnet-configuration</a>
		</li><li><div>The first-time creation of the service can take up to 6h. I made a test in the Central Canada region, and the first creation took about 3 hours and 17 minutes.
</div><p><img src="image002.jpg@01D46F67.9FE6E190" alt="" />
			</p></li></ul><p>
 </p><p>
 </p><h1>Migrate to an Azure Virtual Machine with SQL server pre-installed (IaaS)
</h1><p>If it is not yet possible to migrate your SQL Server 2008 databases to SQL Server 2017, and to remain covered by support, there is the ability to move your databases to a SQL Server 2008 hosted in a Azure virtual machine (VM). To do this, you can directly provision a virtual machine with SQL Server 2008 from an existing Azure VM Template. This saves time and makes sure that you have the right technology base to move your databases.
</p><p>Below is an example of the models available from the Azure portal.   
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/11/110118_1412_SQLServer204.png" alt="" />
	</p><p>Once the virtual machine is provisioned from templates, it is no more or less a migration to another SQL server, with a difference anyway, it is that we will have to transfer the data to Azure, so that they are accessible by the virtual machine . Below, all possible ways to move your data bases to an Azure virtual machine with SQL Server:
</p><ul><li>Perform on-premises backup using compression and manually copy the backup file into the Azure virtual machine
</li><li>Perform a backup to URL and restore into the Azure virtual machine from the URL
</li><li>Detach and then copy the data and log files to Azure blob storage and then attach to SQL Server in Azure VM from URL
</li><li>Convert on-premises physical machine to Hyper-V VHD, upload to Azure Blob storage, and then deploy as new VM using uploaded VHD
</li><li>Ship hard drive using Windows Import/Export Service
</li><li>If you have an AlwaysOn deployment on-premises, use the <a href="https://docs.microsoft.com/en-us/azure/virtual-machines/windows/sqlclassic/virtual-machines-windows-classic-sql-onprem-availability">Add Azure Replica Wizard</a> to create a replica in Azure and then failover, pointing users to the Azure database instance
</li><li>Use SQL Server <a href="https://msdn.microsoft.com/library/ms151176.aspx">transactional replication</a> to configure the Azure SQL Server instance as a subscriber and then disable replication, pointing users to the Azure database instance
</li></ul><p>
 </p><p>I would like to finish this article by a big thanks to <a href="https://www.linkedin.com/in/frédéric-pichaut-970ab640/">Frédéric Pichaut</a> and <a href="https://www.linkedin.com/in/nicosoukoff/">Nicolas Soukoff</a> who have completed and detailed the prerequisite part, strong of their great experience with SQL Server. One MS Power! Merci!
</p><p>For those who will be in Montreal, I will meet you on November 28th, 2018 at Tech Summit:<a href="https://www.microsoftevents.com/profile/web/index.cfm?PKwebID=0x1023303abcd&amp;wt.mc_id=AID737011_QSG_SCL_276355">https://www.microsoftevents.com/profile/web/index.cfm?PKwebID=0x1023303abcd&amp;wt.mc_id=AID737011_QSG_SCL_276355</a>
	</p><p><a href="https://www.linkedin.com/in/mercierfranck/">Franck Mercier</a>
	</p><p>
 </p>]]></content:encoded>
    </item>
    <item>
      <title>Fin de vie de SQL Server 2008</title>
      <link>https://docs.microsoft.com/archive/blogs/franmer/fin-de-vie-de-sql-server-2008</link>
      <pubDate>Thu, 01 Nov 2018 14:03:58 GMT</pubDate>
      <dc:creator><![CDATA[Franck Mercier]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/franmer/?p=13635</guid>
      <description><![CDATA[Le 9 Juillet 2019 sera la fin du support pour les versions 2008 et 2008 R2 de SQL Server. Il est...]]></description>
      <content:encoded><![CDATA[<p>Le 9 Juillet 2019 sera la fin du support pour les versions 2008 et 2008 R2 de SQL Server. Il est encore temps pour migrer vos serveurs vers la nouvelle version de SQL Server. Et pourquoi pas en profiter pour migrer vers Azure. D'autant plus qu'un nouveau service, Azure, SQL Managed Instance (MI), est désormais disponible en version « GA » depuis Octobre 2018, et permet une compatibilité proche des 100% avec un SQL Server installé sur site.
</p><p>Enfin, dans le cas d'applications ne pouvant pas être migrées dans les prochains mois, il existe la possibilité de les héberger dans des machines virtuelles Azure, grâce aux modèles de machines embarquant directement SQL server, et de bénéficier dans ce cas d'une extension de support supplémentaire de 3 ans. 
</p><p>Dans cet article, nous allons voir, en fonction des situations, quelles sont les options possibles pour continuer à utiliser vos applications dans les meilleures conditions de supports et de fonctionnalités.
</p><p>Ci-dessous, voici les 4 possibilités de migration :
</p><ul><li>Migration, sur site, vers la version 2017 (Quand cela est possible pour vos applications)
</li><li>Migration vers SQL Database en mode PaaS (Quand cela est possible pour vos applications)
</li><li>Migration vers Azure SQL Database Managed Instance, qui propose une compatibilité avec SQL Server proche de 100%
</li><li>Dans le cas d'applications difficiles à migrer dans les prochains mois, déploiement dans une machine virtuelle Azure avec les modèles de machine virtuelle SQL Server 2008
</li></ul><h1>Pré requis
</h1><p>En règle générale le processus de migration ressemble aux étapes illustrées ci-dessous. Même si au final, il existe de nombreuses manières d'exécuter un plan de migration, cela reste un projet à part entière : 
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/11/110118_1403_FindeviedeS1.png" alt="" />
	</p><p>La partie découverte peut se réaliser avec l'outil MAP Toolkit :
</p><p><a href="https://docs.microsoft.com/Fr-fr/previous-versions//bb977556(v=technet.10)">https://docs.microsoft.com/Fr-fr/previous-versions//bb977556(v=technet.10)</a>
	</p><p>Cependant, quelle que soit la solution envisagée, il est de bon augure de réaliser les tâches suivantes avant toute migration :
</p><p><strong>Sur le Server SQL source</strong> :
</p><ul><li><span style="color:black">Vérifier que le dernier Service Pack est bien appliqué 
</span></li><li><span style="color:black">Reconstruire les index (si les index sont très fragmentés)
</span></li><li>Vérifier l'intégrité de votre base de données avec <a href="https://docs.microsoft.com/fr-fr/sql/t-sql/database-console-commands/dbcc-checkdb-transact-sql?view=sql-server-2017">DBCC CHECKDB</a> () (ou sur une copie, car cette opération peut prendre du temps)
</li><li>Noter si la base de données n'est pas liée à un plan de maintenance
</li><li>Noter la présence de serveurs liés
</li><li>Noter si l'agent SQL est utilisé
</li><li>Faire un backup complet
</li></ul><p><strong>Sur la cible</strong> :
</p><ul><li><div>Après restauration, vérifier à nouveau l'intégrité de votre base de données avec DBCC CHECKDB
</div><ul><li>Faire un DBCC_CHECKDB  WITH DATA_PURITY : <a href="https://docs.microsoft.com/fr-fr/sql/t-sql/database-console-commands/dbcc-checkdb-transact-sql?view=sql-server-2017">https://docs.microsoft.com/fr-fr/sql/t-sql/database-console-commands/dbcc-checkdb-transact-sql?view=sql-server-2017</a>  
</li></ul></li><li>Faire un DBCC UPDATEUSAGE (<a href="https://docs.microsoft.com/fr-fr/sql/t-sql/database-console-commands/dbcc-updateusage-transact-sql?view=sql-server-2017">https://docs.microsoft.com/fr-fr/sql/t-sql/database-console-commands/dbcc-updateusage-transact-sql?view=sql-server-2017</a>) 
</li><li>Mettre à jour les statistiques
</li><li>Reconstruire les index
</li><li>Vérifier le mode de compatibilité (faire très attention, la base de données utilisera le nouveau <em>Cardinality Estimator</em> introduit avec SQL 2014)
</li></ul><h1>Migration vers SQL Server 2017 (sur site)
</h1><p>Ici, nous sommes dans un scénario classique de migration. Avec la version 2017, il est possible soit de passer par une sauvegarde puis une restauration de la base de données, soit utiliser l'outil Data Migration Assistant (DMA). 
</p><p>En plus des prérequis détaillés plus haut dans cet article, sur le serveur cible qui héberge SQL Server 2017 :
</p><ul><li>Utiliser un système d'exploitation compatible : <a href="https://docs.microsoft.com/fr-fr/sql/sql-server/install/hardware-and-software-requirements-for-installing-sql-server?view=sql-server-2017">https://docs.microsoft.com/fr-fr/sql/sql-server/install/hardware-and-software-requirements-for-installing-sql-server?view=sql-server-2017</a>
		</li><li>Vérifier l'espace des différents disques (TempDB, Logs, Data)
</li><li>Recréer les plans de maintenance, les serveurs liés et autres agents SQL si besoin
</li></ul><p>Enfin, vérifiez aussi les fonctionnalités dépréciées dans la version SQL Server 2017 : <a href="https://docs.microsoft.com/fr-fr/sql/database-engine/deprecated-database-engine-features-in-sql-server-2017?view=sql-server-2017">https://docs.microsoft.com/fr-fr/sql/database-engine/deprecated-database-engine-features-in-sql-server-2017?view=sql-server-2017</a>
	</p><p>
 </p><p>En ce qui concerne la migration elle-même, il est possible d'utiliser les méthodes suivantes:  
</p><h3>Sauvegarde et restauration des bases de données
</h3><ul><li>Depuis la version 2017, il est possible de créer une base de données depuis la sauvegarde d'une base en version 2005 ou supérieure. La documentation détaillée de cette fonctionnalité est disponible sur cette page web : <a href="https://docs.microsoft.com/fr-fr/sql/relational-databases/databases/copy-databases-with-backup-and-restore?view=sql-server-2017">https://docs.microsoft.com/fr-fr/sql/relational-databases/databases/copy-databases-with-backup-and-restore?view=sql-server-2017</a>
		</li></ul><p>
 </p><h3>Data Migration Assistant
</h3><ul><li><div>Data Migration Assistant (DMA) est un outil <a href="https://www.microsoft.com/en-us/download/details.aspx?id=53595">téléchargeable ici</a>, qui va vous servir à : 
</div><ul><li><strong>Faire une évaluation de vos bases de données à migrer</strong>, afin d'évaluer l'effort de migration. Une documentation complète se trouve sur cette page web : <a href="https://docs.microsoft.com/fr-fr/sql/dma/dma-assesssqlonprem?view=sql-server-2017">https://docs.microsoft.com/fr-fr/sql/dma/dma-assesssqlonprem?view=sql-server-2017</a>
				</li><li><strong>Faire la migration</strong>. DMA peut faire la migration de manière automatique. Une documentation complète du process de migration est disponible ici : <a href="https://docs.microsoft.com/fr-fr/sql/dma/dma-migrateonpremsql?view=sql-server-2017">https://docs.microsoft.com/fr-fr/sql/dma/dma-migrateonpremsql?view=sql-server-2017</a>
				</li></ul></li></ul><h1>Migration vers SQL Database (PaaS)
</h1><p>C'est une autre possibilité de migration, et aussi l'occasion de moderniser votre infrastructure de donnée avec les solutions Cloud. De plus, vous bénéficierez de tous les avantages d'un service managé (Pas de gestion de matériel, données répliquées en 3 exemplaires, gestion des mises à jour transparentes, élasticité,  ….).
</p><p>Encore une fois, il existe plusieurs méthodes pour migrer vos bases SQL vers SQL Database. Mais principalement, les 3 méthodes illustrées ci-dessous peuvent être utilisées, après avoir consulté les prérequis détaillés plus haut :
</p><p style="text-align: center"><img src="https://msdnshared.blob.core.windows.net/media/2018/11/110118_1403_FindeviedeS2.png" alt="" />
	</p><p>
 </p><ul><li>Réplication transactionnelle. Une documentation se trouve ici : <a href="https://docs.microsoft.com/fr-fr/azure/sql-database/sql-database-cloud-migrate">https://docs.microsoft.com/fr-fr/azure/sql-database/sql-database-cloud-migrate#method-2-use-transactional-replication</a>
		</li><li>Export / Import d'un fichier BACPAC : <a href="https://docs.microsoft.com/fr-fr/azure/sql-database/sql-database-import">https://docs.microsoft.com/fr-fr/azure/sql-database/sql-database-import</a>
		</li><li>Utilisation de <a href="https://docs.microsoft.com/fr-fr/azure/sql-database/sql-database-migrate-your-sql-server-database">DMA</a>. Attention, cette opération rendra inaccessible votre base de données durant le process de migration !
</li></ul><p>
 </p><p>Afin de mesurer l'impact de la migration, il est possible d'utiliser l'outil <em>Database Experimentation Assistant</em> (DEA). Cet outil permet la capture de traces, sur un serveur existant, afin d'être rejouées sur SQL Database, SQL Managed instance ou SQL sur Linux. DEA peut être téléchargé ici : <a href="https://www.microsoft.com/en-us/download/details.aspx?id=54090">https://www.microsoft.com/en-us/download/details.aspx?id=54090</a>
	</p><p>Enfin, comme je l'ai déjà mentionné, il existe d'autres manières de migrer ses bases de données comme l'utilisation de <em>SQL Server Integration Services</em> (SSIS) ou <em>Azure Data Factory v2</em>.  
</p><p>
 </p><h1>Migration vers Azure SQL Database Managed Instance (PaaS)
</h1><p>SQL Database Managed Instance (MI) est un service managé (PaaS) offrant une compatibilité avec SQL server proche de 100%, tout en supportant des fonctionnalités qui ne sont pas présentes dans SQL Database comme :
</p><ul><li>Fonction native de sauvegarde / restauration
</li><li>Server lié
</li><li>CLR
</li><li>SQL Agent
</li><li>DB mail (SMTP externe)
</li><li>…
</li></ul><p>De plus, SQL Database MI fonctionne dans son propre VNet, ce qui permet de renforcer la sécurité de votre base de données…. Mais au détriment, aujourd'hui, d'un manque d'intégration avec, par exemple, les autres services Azure.
</p><p>Une vue d'ensemble complète de SQL Database MI est disponible sur cette page web : <a href="https://docs.microsoft.com/fr-fr/azure/sql-database/sql-database-managed-instance">https://docs.microsoft.com/fr-fr/azure/sql-database/sql-database-managed-instance#sql-features-supported</a>
	</p><h2>Migration vers SQL Database Managed Instance
</h2><p>Encore une fois, après avoir vérifié les prérequis expliqués plus haut dans cet article, il existe plusieurs solutions : 
</p><ul><li>Azure Database Migration Service (Qui utilisera DMA pour la partie évaluation de l'effort de migration) : <a href="https://docs.microsoft.com/fr-fr/azure/dms/dms-overview">https://docs.microsoft.com/fr-fr/azure/dms/dms-overview</a>
		</li><li>La restauration native à partir d'une URL. J'ai expliqué dans un article, qui date un peu , comment faire ce type de sauvegarde (article en Français): <a href="https://blogs.technet.microsoft.com/franmer/2013/11/15/sql-server-2014-intgration-avec-le-stockage-azure/">https://blogs.technet.microsoft.com/franmer/2013/11/15/sql-server-2014-intgration-avec-le-stockage-azure/</a>. Sinon cet article est plus récent : <a href="https://docs.microsoft.com/fr-fr/sql/relational-databases/backup-restore/sql-server-backup-to-url?view=sql-server-2017">https://docs.microsoft.com/fr-fr/sql/relational-databases/backup-restore/sql-server-backup-to-url?view=sql-server-2017</a>
		</li></ul><p>Globalement la sauvegarde à partir d'une URL va suivre le cheminement suivant :
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/11/110118_1403_FindeviedeS3.png" alt="" />
	</p><p>Tous les détails, pour chaque méthode de migration, sont disponibles sur le lien suivant :
</p><p><a href="https://docs.microsoft.com/fr-fr/azure/sql-database/sql-database-managed-instance-migrate">https://docs.microsoft.com/fr-fr/azure/sql-database/sql-database-managed-instance-migrate</a>
	</p><p>
 </p><p><strong>Attention</strong> aux 2 points suivants :
</p><ul><li>SQL Database Managed Instance doit être déployé au sein d'un réseau virtuel. L'article suivant donne les détails de configuration : <a href="https://docs.microsoft.com/fr-fr/azure/sql-database/sql-database-managed-instance-vnet-configuration">https://docs.microsoft.com/fr-fr/azure/sql-database/sql-database-managed-instance-vnet-configuration</a>
		</li><li><div>La première création du service peut prendre jusqu'à 6h. J'ai réalisé un test dans la région Canada Central, et la première création à durée environ 3h15.
</div><p><img src="image002.jpg@01D46F67.9FE6E190" alt="" />
			</p></li></ul><p>
 </p><h1>Migration vers une machine virtuelle Azure avec SQL Server (IaaS)
</h1><p>Dans le cas où il n'est pas encore possible de migrer vos bases SQL server 2008 vers SQL Server 2017, et pour rester couvert par le support, il existe la possibilité de déplacer vos bases de données vers un serveur SQL 2008 hébergé dans une machine virtuelle Azure. Pour cela, il est possible de provisionner directement, à partir d'un modèle existant, une machine virtuelle avec SQL Server 2008. Cela permet de gagner du temps et d'être certain d'avoir la bonne base technologique pour assurer le déplacement de vos bases de données.
</p><p>Ci-dessous un exemple des modèles disponibles depuis le portail Azure.   
</p><p>
 </p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/11/110118_1403_FindeviedeS4.png" alt="" />
	</p><p>
 </p><p>Une fois la machine virtuelle provisionnée depuis les modèles proposés, il ne s'agit, ni plus ni moins, d'une migration vers un autre serveur SQL, avec une différence quand même, c'est qu'il va falloir transférer les données vers Azure, afin qu'elles soient accessibles par la machine virtuelle. Mais sinon, toutes les méthodes ci-dessous sont possibles pour bouger vos bases de données vers une machine virtuelle Azure hébergeant SQL Server :
</p><ul><li>Effectuer une sauvegarde locale par compression et copier manuellement le fichier de sauvegarde dans la machine virtuelle Azure
</li><li>Effectuer une sauvegarde vers une URL et exécuter une restauration dans la machine virtuelle Azure à partir de cette URL
</li><li>Détacher, puis copier les fichiers journaux et de données vers le stockage d'objets blob Azure, puis les rattacher à SQL Server dans la machine virtuelle Azure depuis une URL
</li><li>Convertir une machine physique locale en disque dur virtuel Hyper-V, effectuer un téléchargement vers le stockage d'objets Blob Azure, puis exécuter un déploiement en tant que nouvelle machine virtuelle en utilisant le disque dur virtuel téléchargé
</li><li>Expédition du disque dur avec le Service d'importation/exportation Windows : https://docs.microsoft.com/fr-fr/azure/storage/common/storage-import-export-service
</li><li>Si vous disposez d'un déploiement AlwaysOn local, utilisez l' <a href="https://docs.microsoft.com/fr-fr/azure/virtual-machines/windows/sqlclassic/virtual-machines-windows-classic-sql-onprem-availability">Assistant Ajout d'un réplica Azure</a> pour créer un réplica dans Azure, puis basculez en dirigeant les utilisateurs vers l'instance de base de données Azure
</li><li>Utiliser la <a href="https://msdn.microsoft.com/library/ms151176.aspx">réplication transactionnelle</a> de SQL Server pour configurer l'instance Azure SQL Server en tant qu'abonné, puis désactiver la réplication en dirigeant les utilisateurs vers l'instance de base de données Azure
</li></ul><p>Toutes les méthodes énoncées ci-dessus sont détaillées dans l'article suivant :
</p><p><a href="https://docs.microsoft.com/fr-fr/azure/virtual-machines/windows/sql/virtual-machines-windows-migrate-sql">https://docs.microsoft.com/fr-fr/azure/virtual-machines/windows/sql/virtual-machines-windows-migrate-sql</a>
	</p><p>
 </p><p>J'aimerai terminer cet article par un grand merci à <a href="https://www.linkedin.com/in/frédéric-pichaut-970ab640/">Frédéric Pichaut</a> et <a href="https://www.linkedin.com/in/nicosoukoff/">Nicolas Soukoff</a> qui ont complété et détaillé la partie prérequis, fort de leur grande expérience avec SQL Server. One MS Power ! Merci les gars !
</p><p>Pour ceux qui seront à Montréal, je vous donne rendez-vous le 28 novembre 2018 au Tech Summit : <a href="https://www.microsoftevents.com/profile/web/index.cfm?PKwebID=0x1023303abcd&amp;wt.mc_id=AID737011_QSG_SCL_276355">https://www.microsoftevents.com/profile/web/index.cfm?PKwebID=0x1023303abcd&amp;wt.mc_id=AID737011_QSG_SCL_276355</a>
	</p><p>
 </p><p><a href="https://www.linkedin.com/in/mercierfranck/">Franck Mercier</a>
	</p><p>
 </p>]]></content:encoded>
    </item>
    <item>
      <title>Azure Custom Vision in action</title>
      <link>https://docs.microsoft.com/archive/blogs/franmer/azure-custom-vision-in-action</link>
      <pubDate>Fri, 17 Aug 2018 14:30:50 GMT</pubDate>
      <dc:creator><![CDATA[Franck Mercier]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/franmer/?p=13585</guid>
      <description><![CDATA[Azure platform offers many ready-to-use cognitive services, allows you easily enrich your...]]></description>
      <content:encoded><![CDATA[<p>Azure platform offers many ready-to-use cognitive services, allows you easily enrich your applications with innovative features. 
</p><p>In this article we will see how to use the Custom Vision service. We will train a model to learn how to recognize some types of coats. We will then test this model and finally we will see how to use it within an application.
</p><p>
 </p><h1>Prerequisite
</h1><ul><li><a href="https://azure.microsoft.com/fr-fr/free/">Azure Account </a>
		</li><li><a href="https://visualstudio.microsoft.com/vs/whatsnew/">Visual Studio 2017</a>
		</li></ul><p>The part about the notebook can be done, among others, with:
</p><ul><li><a href="https://notebooks.azure.com/">Microsoft Azure Notebooks</a> service
</li><li>The "Data Science" virtual machine available from <a href="https://portal.azure.com">Azure </a>portal
</li></ul><p>In this article, we will use the "Data Science" virtual machine
</p><h1>Creating "Data Science" virtual machine
</h1><ul><li>Connect to the Azure Portal: <a href="https://portal.azure.com">https://portal.azure.com</a>
		</li><li>Click on " <strong>Create a resource</strong> », and then search for the virtual machine "Data Science"
</li></ul><p>
 </p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom1.png" alt="" />
	</p><p>Select " <strong>Data Science Virtual Machine for Linux (Ubuntu)</strong> ». Then Click on the button "<strong>Create</strong>"
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom2.png" alt="" />
	</p><p>
 </p><p>
 </p><p>Fill in the virtual machine creation form 
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom3.png" alt="" />
	</p><p>At the end of the process click on the "<strong>Create</strong>" button
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom4.png" alt="" />
	</p><p>
 </p><p>The virtual machine is now created. We will connect on its Jupyter server. The connection is an URL type:
</p><p><a>https://&lt; Your_VM_IPAddress &gt;: 8000</a>
	</p><p>In our case, this address will be:
</p><p><a href="https://40.86.210.115:8000">https://40.86.210.115:8000</a>
	</p><p>
 </p><p>The virtual machine IP address can be found on the Azure portal:
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom5.png" alt="" />
	</p><p>
 </p><p>The following window may appear. Click on " <strong>Details,</strong> then <strong>Go on the Web page</strong> » 
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom6.png" alt="" />
	</p><p>
 </p><p>In the login window, enter the name and password you have used when creating the virtual machine:
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom7.png" alt="" />
	</p><p>After a few seconds you must land on the Jupyter server home page. 
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom8.png" alt="" />
	</p><p>We will create a folder to facilitate our work. Click on "<strong>New</strong>" then "<strong>Folder</strong>"
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom9.png" alt="" />
	</p><p>
 </p><p>Check the box to the left of the newly created folder (the folder is named « <em>Untitled Folder »), </em>then click the button « <strong>Rename</strong> » on top of the page.
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom10.png" alt="" />
	</p><p>Rename the folder and then click on the "<strong>Rename</strong>" button
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom11.png" alt="" />
	</p><p>
 </p><p>
 </p><h1>Creating the Notebook
</h1><p>Enter the previously created folder. Click on the button "<strong><em>New"</em></strong>  then "<strong><em>Python 3"</em></strong>
	</p><p>
 </p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom12.png" alt="" />
	</p><p>Once the <em>Notebook</em> created, click "<strong>Untitled</strong>" and give it a name. Click on "<strong>Rename</strong>"
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom13.png" alt="" />
	</p><p>
 </p><h2>Download pictures
</h2><p>In the first cell of the Notebook, copy the code below to recover the training and tests images 
</p><p>! curl-O <a href="https://canadastore.blob.core.windows.net/franmerpictures/Pictures.zip">https://canadastore.blob.core.windows.net/franmerpictures/Pictures.zip</a>
	</p><p>Then click « <strong>run</strong> » on the toolbar (or use the combination key "<strong><em>Shift Enter"</em></strong> or "<strong><em>Ctrl Enter"</em></strong>). For the rest of the article, after copying the code in the cells, think well to execute the code.
</p><p>
		<img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom14.png" alt="" />
	</p><p>If everything goes well, the <em>Pictures.zip</em> file must appear in your folder
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom15.png" alt="" />
	</p><p>We will now unzip the file. Use the command below in a new cell:
</p><p>!  unzip Pictures.zip
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom16.png" alt="" />
	</p><p>
 </p><p>
 </p><p><strong>Attention</strong>: star between the hooks, means the code is still running. Wait until the star disappears.
</p><p style="text-align: center"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom17.png" alt="" />
	</p><p>
 </p><p>Three new files had to appear:
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom18.png" alt="" />
	</p><h2>displaying an image
</h2><p>We will display an image and see some basic functions to deal with pictures. We will use « <em>Matplotlib</em> » library. « <em>Matplotlib</em> » documentation can be found here: <a href="https://matplotlib.org/">https://matplotlib.org/</a>.
</p><p>Copy the code below to a new cell:
</p><p style="margin-left: 36pt">#<em>Afficher une image / Display a picture</em>
	</p><p style="margin-left: 36pt"># <em>Importation de librairie matplotlib / Import the matplotlib libraries</em>
	</p><p style="margin-left: 36pt">import matplotlib.pyplot as plt
</p><p style="margin-left: 36pt">import matplotlib.image as im
</p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt">img = im.imread('hardshell_jackets/10116634x1038116_zm.jpeg')
</p><p style="margin-left: 36pt">imgplot = plt.imshow(img)
</p><p style="margin-left: 36pt">
 </p><p>In the first run, the following message may appear. This will not affect the outcome.
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom19.png" alt="" />
	</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom20.png" alt="" />
	</p><h2>Retrieve picture information
</h2><p>An image is intrinsically an array of values of <a href="https://en.wikipedia.org/wiki/Pixel">pixels</a> (Picture Element) and It is important to be able to recover picture  information, in order to use them with object recognition algorithms. Below is a sample code for retrieving certain information. Copy and paste it in a new cell. Don't forget to run the code.
</p><p style="margin-left: 36pt">#<em>Information sur l'image / Picture's information</em>
	</p><p style="margin-left: 36pt">print ("Picture Shape: ")
</p><p style="margin-left: 36pt">print(img.shape)
</p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt">#<em>Total number of pixels is accessed by img.size:</em>
	</p><p style="margin-left: 36pt">print ("Number of pixels: ")
</p><p style="margin-left: 36pt">print (img.size)
</p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt">#<em>Image datatype is obtained by img.dtype:</em>
	</p><p style="margin-left: 36pt">print("Picture data type:")
</p><p style="margin-left: 36pt">print(img.dtype)
</p><p>
 </p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom21.png" alt="" />
	</p><p>
 </p><h1>Integration with the "Custom Vision" cognitive service
</h1><p>Microsoft offers many Cognitive Services. The complete list is available through the following link: <a href="https://azure.microsoft.com/en-us/services/cognitive-services/directory/">https://azure.microsoft.com/en-us/services/cognitive-services/directory/</a>
	</p><p>In addition, these services may be called as a web service to return the prediction results. 
</p><p>In this example, we will use the service "<strong>Custom Vision"</strong>. This service is available through the following link: <a href="https://customvision.ai/">https://customvision.ai/</a>.
</p><p>But before, we still have small preparations to do in our Notebook.
</p><h2>Installing the Custom Vision SDK
</h2><p>As a first step, we will check the presence of "Pip" and its update.  "Pip" is a tool for installing Python packages. In a new cell of the Notebook, copy the following code:
</p><p style="margin-left: 36pt">#<em>installation de pip / pip installation</em>
	</p><p style="margin-left: 36pt">import sys
</p><p style="margin-left: 36pt">! {sys.executable} -m pip freeze
</p><p style="margin-left: 36pt">! {sys.executable} -m pip --version
</p><p style="margin-left: 36pt">! {sys.executable} -m pip install --upgrade pip
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom22.png" alt="" />
	</p><p>
 </p><p>
 </p><p>From your notebook, enter the following command: (So we use " Pip "To Install the Package Of the "Custom Vision" cognitive service) :
</p><p style="margin-left: 36pt">#Installation du SDK Custom Vision / Install the Custom Vision SDK
</p><p style="margin-left: 36pt">! {sys.executable} -m pip install azure-cognitiveservices-vision-customvision
</p><p>
 </p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom23.png" alt="" />
	</p><p> 
 </p><h2>Configuring the "Custom Vision" cognitive service
</h2><p>We will now create a "Custom Vision" service via the following link:
</p><p><a href="https://customvision.ai">Https://customvision.ai</a>
	</p><p>Click on " <strong>Sign In</strong> »
</p><p>
 </p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom24.png" alt="" />
	</p><p>Can choose to click on "Continue with trial" or click on "Sign Up for Azure". For our example, we will choose " <strong>Continue with trial</strong> » :
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom25.png" alt="" />
	</p><p>Once the service is created, retrieve the information from your service by clicking the gear in the top right of the window
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom26.png" alt="" />
	</p><p>Then recover the values of your keys 
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom27.png" alt="" />
	</p><p>Return to your Jupyter notebook to assign the key values to the variables:
</p><p style="margin-left: 36pt"># Assignez les clefs de votre service "Custom Vision" aux variables / Assign your Custom service keys to variables
</p><p style="margin-left: 36pt">training_key = 'c5926d0852854f459c85facff519c759'
</p><p style="margin-left: 36pt">prediction_key = '32446a7de71b496798d38fded67fc2da'
</p><p style="margin-left: 36pt">
 </p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom28.png" alt="" />
	</p><p>
 </p><h2>Creating a Custom Vision project
</h2><p>From the notebook, we will create a project in the "Custom Vision" cognitive service. In a new cell, copy the code below and run it:
</p><p style="margin-left: 36pt">from azure.cognitiveservices.vision.customvision.training import training_api
</p><p style="margin-left: 36pt">from azure.cognitiveservices.vision.customvision.training.models import ImageUrlCreateEntry
</p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt">trainer = training_api.TrainingApi(training_key)
</p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt"># Create a new project
</p><p style="margin-left: 36pt">print ("Creating project...")
</p><p style="margin-left: 36pt">project = trainer.create_project("MyProject")
</p><p>
 </p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom29.png" alt="" />
	</p><p>
 </p><p>If you return to the "Custom Vison" service web page, you will find a new project:
</p><p style="text-align: center"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom30.png" alt="" />
	</p><p>
 </p><h2>Labels creation
</h2><p>Before adding images to the service, we will create our first labels to identify the images.
</p><p>Add the following code to a new cell and run the code:
</p><p style="margin-left: 36pt"># <em>Création des labels les images / Add tags for pictures</em>
	</p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt">print("Creating tags")
</p><p style="margin-left: 36pt">hardshell_tag = trainer.create_tag(project.id,"Hardshell")
</p><p style="margin-left: 36pt">insulated_tag = trainer.create_tag(project.id,"Insulated")
</p><p style="margin-left: 36pt">print("Tags created")
</p><p>
 </p><p style="text-align: center"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom31.png" alt="" />
	</p><p>
 </p><h2>Loading Images
</h2><p>Now let's add the images in our custom vision project and add the labels at the same time. Copy and run the code below in a new cell:
</p><p style="margin-left: 36pt"># Téléchargez les images / Upload pictures
</p><p style="margin-left: 36pt">import os
</p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt">print("Adding hardshell images...")
</p><p style="margin-left: 36pt">hardshell_folder = "jacket_images/hardshell_jackets"
</p><p style="margin-left: 36pt">for file in os.listdir(os.fsencode("jacket_images/hardshell_jackets")):
</p><p style="margin-left: 36pt">    with open(hardshell_folder + "/" + os.fsdecode(file),mode="rb") as Hardshell_img_data:
</p><p style="margin-left: 36pt">        trainer.create_images_from_data(project.id,Hardshell_img_data,[hardshell_tag.id])
</p><p style="margin-left: 36pt">        
 </p><p style="margin-left: 36pt">print("Adding insulated images...")
</p><p style="margin-left: 36pt">insulated_folder = "jacket_images/insulated_jackets"
</p><p style="margin-left: 36pt">for file2 in os.listdir(os.fsencode("jacket_images/insulated_jackets")):
</p><p style="margin-left: 36pt">    with open(insulated_folder + "/" + os.fsdecode(file2),mode="rb") as insulated_img_data:
</p><p style="margin-left: 36pt">        trainer.create_images_from_data(project.id,insulated_img_data,[insulated_tag.id])
</p><p style="margin-left: 36pt">        
 </p><p style="margin-left: 36pt">print("Done !")
</p><p>
 </p><p style="text-align: center;margin-left: 36pt"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom32.png" alt="" />
	</p><p style="text-align: center;margin-left: 36pt">
 </p><p style="text-align: center;margin-left: 36pt">
 </p><p style="margin-left: 36pt">Check the presence of the images in the web interface of the cognitive service, and check that the images have the right label.
</p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom33.png" alt="" />
	</p><p>
 </p><p>
 </p><p>
 </p><p>
 </p><p>
 </p><h1>Training of the project
</h1><p>After adding images and set the different labels, we can now train a model for identifying our images.
</p><p>In a new cell, copy and run the code below:
</p><p style="margin-left: 36pt"><em>#Entrainement du projet / Train the project
</em></p><p style="margin-left: 36pt"><em>import time
</em></p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt"><em>print("Training....")
</em></p><p style="margin-left: 36pt"><em>iteration = trainer.train_project(project.id)
</em></p><p style="margin-left: 36pt"><em>print (iteration.status)
</em></p><p style="margin-left: 36pt"><em>while (iteration.status != "Completed"):
</em></p><p style="margin-left: 36pt"><em>    iteration = trainer.get_iteration(project.id,iteration.id)
</em></p><p style="margin-left: 36pt"><em>    print("Training status: " + iteration.status)
</em></p><p style="margin-left: 36pt"><em>    time.sleep(1)
</em></p><p style="margin-left: 36pt">    
 </p><p style="margin-left: 36pt"><em># Set this iteration of the project as the default.
</em></p><p style="margin-left: 36pt"><em>trainer.update_iteration(project.id,iteration.id,is_default=True)
</em></p><p style="margin-left: 36pt"><em>print("Done!")
</em></p><p style="margin-left: 36pt">
 </p><p style="text-align: center"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom34.png" alt="" />
	</p><p>
 </p><p>
 </p><p>If we check in the web interface of the cognitive service, a first iteration of our model was created.
</p><p style="text-align: center"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom35.png" alt="" />
	</p><p style="text-align: center">
 </p><p>
 </p><h1>Test the model
</h1><p>Now that the model has been trained, we will test it with another set of images
</p><p>As a first step, we will create a function to convert images and send a data value to the cognitive service endpoint.
</p><p>To do this conversion, we will create a function. Copy the code below into a new cell:
</p><p style="margin-left: 36pt">def read_image_data(img_path):
</p><p style="margin-left: 36pt">    import numpy as np
</p><p style="margin-left: 36pt">    from io import BytesIO
</p><p style="margin-left: 36pt">    import matplotlib.pyplot as plt
</p><p style="margin-left: 36pt">    
 </p><p style="margin-left: 36pt">    # Load the numpy array
</p><p style="margin-left: 36pt">    #imgArray = np.load(img_path)
</p><p style="margin-left: 36pt">    imgArray = im.imread(img_path)
</p><p style="margin-left: 36pt">    # Write the array data to a stream
</p><p style="margin-left: 36pt">    imageStream = BytesIO()
</p><p style="margin-left: 36pt">    plt.imsave(imageStream, imgArray)
</p><p style="margin-left: 36pt">    # Read the stream from the beginning
</p><p style="margin-left: 36pt">    imageStream.seek(0)
</p><p style="margin-left: 36pt">    return imageStream.read()
</p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt">print ('read_image_data function created!')
</p><p>
 </p><p style="text-align: center"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom36.png" alt="" />
	</p><p>
 </p><p>
 </p><p>We will use the model we have trained to make predictions on test images. We will also use the function created previously to convert the images before sending them to the model.
</p><p>In a new cell in your Notebook, copy the code below:
</p><p style="margin-left: 36pt"><span style="font-size:9pt">import os
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">import time
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">import numpy as np 
</span></p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt"><span style="font-size:9pt">#Importation du point de terminaison de prédiction / Import the prediction endpoint
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">from azure.cognitiveservices.vision.customvision.prediction import prediction_endpoint
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">from azure.cognitiveservices.vision.customvision.prediction.prediction_endpoint import models
</span></p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt"><span style="font-size:9pt">#Création d'une instance du point de terminaison de prédiction
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">#Create an instance of the prediction endpoint 
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">predictor = prediction_endpoint.PredictionEndpoint(prediction_key)
</span></p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt"><span style="font-size:9pt">#Boucle sur l'ensemble des images / Loop through the test images
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">folder = 'Test'
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">files = os.listdir(folder)
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">i=1
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">x = np.linspace(0,10)
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">y = np.sin(x)
</span></p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt"><span style="font-size:9pt">for file in sorted(files):
</span></p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt"><span style="font-size:9pt">    #Les images sont traitées dans l'ordre / process files in order
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">    #Récupération du chemin de l'image et lecture des données / Get the file path and read the image data
</span></p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt"><span style="font-size:9pt">    img_path = os.path.join(folder,file) #Test pour savoir si c'est un fichier ou un dossier        
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">    if os.path.isfile(img_path):
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">        print("File name: " + file)  
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">        img = im.imread(img_path)
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">        plt.imshow(img)
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">        plt.show()
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">        #plt.plot(x,y)
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">        #plt.figure(i+1)    
</span></p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt"><span style="font-size:9pt">        img_data = read_image_data(img_path)  
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">        #Récupération des prédictions pour les images / Get the predicted tags for the image
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">        results = predictor.predict_image(project.id, img_data, iteration.id)
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">        fig = plt.figure()
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">        #Affichage des labels et des probabilités / Display the tag name and probability for each prediction
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">        for prediction in results.predictions: 
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">            print ("\t" + prediction.tag_name + ": {0:.2f}%".format(prediction.probability * 100))
</span></p><p style="margin-left: 36pt">            
 </p><p style="margin-left: 36pt"><span style="font-size:9pt">         print('\n')
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">        #Pause technique :) / Technical Delay
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">        time.sleep(0.25)
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">        i=i+1
</span></p><p>
 </p><p style="text-align: justify;margin-left: 18pt"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom37.png" alt="" />
	</p><p>
 </p><p style="margin-left: 36pt">Our model returns predictions to try to identify whether the scanned images are coats or not, and if so, what kind of coat is it. Below a sample of prediction results
<div style="margin-left: 36pt"><table style="border-collapse:collapse" border="0"><colgroup><col style="width:384px" /><col style="width:384px" /><col style="width:384px" /></colgroup><tbody valign="top"><tr><td style="padding-left: 14px;padding-right: 14px"> </td><td style="padding-left: 14px;padding-right: 14px"> </td><td style="padding-left: 14px;padding-right: 14px"> </td></tr></tbody></table></div><p style="margin-left: 36pt">
 </p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom38.png" alt="" />
		</p><h1>Using the cognitive service with Visual Studio
</h1><p style="margin-left: 36pt">
 </p><p>Now that our model is ready, It could be interesting to use the service API to Integrate predictions in an application. Below is a quick illustration of integrating the cognitive service into an application.
</p><p>
 </p><p>Start Visual Studio 2017 and create a "Console App"project.
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom39.png" alt="" />
		</p><p>
 </p><p>Once the project created, go to « <strong>Tools</strong> / <strong>NuGet Package Manager</strong> / <strong>Manage NuGet Packages for Solution</strong>... " and add the Custom Vision Packages as illustrated below:
</p><p>
 </p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom40.png" alt="" />
		</p><p>
 </p><p>
 </p><p>Add the 2 following packages:
</p><p>
 </p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom41.png" alt="" />
		</p><p>
 </p><p>Then in the file "Program.cs" add the code below. Replace the keys by those of your cognitive service project
</p><p>
 </p><p style="margin-left: 36pt"><span style="color:blue;font-family:Consolas;font-size:9pt">using<span style="color:black"> Microsoft.Cognitive.CustomVision.Prediction;
</span></span></p><p style="margin-left: 36pt"><span style="color:blue;font-family:Consolas;font-size:9pt">using<span style="color:black"> Microsoft.Cognitive.CustomVision.Training;
</span></span></p><p style="margin-left: 36pt"><span style="color:blue;font-family:Consolas;font-size:9pt">using<span style="color:black"> Microsoft.Cognitive.CustomVision.Training.Models;
</span></span></p><p style="margin-left: 36pt"><span style="color:blue;font-family:Consolas;font-size:9pt">using<span style="color:black"> System;
</span></span></p><p style="margin-left: 36pt"><span style="color:blue;font-family:Consolas;font-size:9pt">using<span style="color:black"> System.Collections.Generic;
</span></span></p><p style="margin-left: 36pt"><span style="color:blue;font-family:Consolas;font-size:9pt">using<span style="color:black"> System.IO;
</span></span></p><p style="margin-left: 36pt"><span style="color:blue;font-family:Consolas;font-size:9pt">using<span style="color:black"> System.Linq;
</span></span></p><p style="margin-left: 36pt"><span style="color:blue;font-family:Consolas;font-size:9pt">using<span style="color:black"> System.Threading;
</span></span></p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt"><span style="color:blue;font-family:Consolas;font-size:9pt">namespace<span style="color:black"> myTutorialCustomVision
</span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">{
</span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">
				<span style="color:blue">class<span style="color:black">
						<span style="color:#2b91af">Program<span style="color:black">
							</span></span></span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">    {
</span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">
				<span style="color:green">//private static MemoryStream testImage;<span style="color:black">
					</span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">
				<span style="color:blue">static<span style="color:black">
						<span style="color:blue">void<span style="color:black"> Main(<span style="color:blue">string<span style="color:black">[] args)
</span></span></span></span></span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">        {
</span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">
				<span style="color:blue">var<span style="color:black"> projectID = <span style="color:#a31515">"&lt;YourProjectID&gt;"<span style="color:black">;
</span></span></span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">
				<span style="color:blue">var<span style="color:black"> trainingKey = <span style="color:#a31515">"&lt;YourTrainingKey&gt;"<span style="color:black">;
</span></span></span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">
				<span style="color:blue">var<span style="color:black"> predictionKey = <span style="color:#a31515">"&lt;YourPredictionKey&gt;"<span style="color:black">;
</span></span></span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">
				<span style="color:blue">string<span style="color:black"> imagesPath = <span style="color:maroon">@"..\..\..\myTutorialCustomVision\Images"<span style="color:black">;
</span></span></span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">
				<span style="color:blue">string<span style="color:black">[] imageFiles = Directory.GetFiles(imagesPath, <span style="color:#a31515">"*.jpg"<span style="color:black">);
</span></span></span></span></span></p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">            TrainingApi trainingApi = <span style="color:blue">new<span style="color:black"> TrainingApi() { ApiKey = trainingKey };
</span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">
				<span style="color:blue">var<span style="color:black"> project = trainingApi.GetProjects();
</span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">            Guid myGuid = project[0].Id;
</span></p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">
				<span style="color:blue">var<span style="color:black"> iterations = trainingApi.GetIterations(Guid.Parse(projectID));
</span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">
				<span style="color:blue">var<span style="color:black"> validIterations = iterations.Where(iter =&gt; iter.Status == <span style="color:#a31515">"Completed"<span style="color:black">);
</span></span></span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">
				<span style="color:blue">var<span style="color:black"> lastIterationTrained = validIterations.OrderBy(iter =&gt; iter.LastModified).Last();
</span></span></span></p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt">            
 </p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">            Iteration lastIteration = trainingApi.GetIteration(myGuid, lastIterationTrained.Id);
</span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">            lastIteration.IsDefault = <span style="color:blue">true<span style="color:black">;
</span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">            trainingApi.UpdateIteration(myGuid, lastIteration.Id, lastIteration);
</span></p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt">            
 </p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">
				<span style="color:blue">foreach<span style="color:black"> (var image <span style="color:blue">in<span style="color:black"> imageFiles)
</span></span></span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">            {
</span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">                FileStream fileStream = <span style="color:blue">new<span style="color:black"> FileStream(image, FileMode.Open, FileAccess.Read);
</span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">                PredictionEndpoint endpoint = <span style="color:blue">new<span style="color:black"> PredictionEndpoint() { ApiKey = predictionKey };
</span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">                Console.WriteLine(<span style="color:#a31515">"Making a prediction for picture: "<span style="color:black"> + Path.GetFileName(image));
</span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">
				<span style="color:blue">var<span style="color:black"> result = endpoint.PredictImage(myGuid, fileStream);
</span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">
				<span style="color:blue">foreach<span style="color:black"> (var c <span style="color:blue">in<span style="color:black"> result.Predictions)
</span></span></span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">                {
</span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">                    Console.WriteLine(<span style="color:#a31515">$"\t<span style="color:black">{c.Tag}<span style="color:#a31515">: <span style="color:black">{c.Probability:<span style="color:#a31515">P1<span style="color:black">}<span style="color:#a31515">"<span style="color:black">);
</span></span></span></span></span></span></span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">                }
</span></p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">            }
</span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">            Console.ReadKey();
</span></p><p style="margin-left: 36pt">            
 </p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">        }
</span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">    }
</span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">}
</span></p><p>
 </p><p>
 </p><h2>Test of the application
</h2><p>To test the application and the predictions, I added a folder images in the "Solution Explorer" and I have copied 2 images in this folder
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom42.png" alt="" />
		</p><p>
 </p><p>
 </p><p>
 </p><h2>Result
</h2><p>The application will return, for each image, a prediction for each Labels.  
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom43.png" alt="" />
		</p><p>
 </p><p><span style="color:black;font-size:9pt">You may get the error " <span style="font-family:Segoe UI">Operation returned an invalid status code '429' </span>» If you are testing with a large number of images. Often this error comes from the fact that your service is in trial version or undersized. To correct the problem, just change the "Pricing tier" on the Custom Vision Web page, in the "<strong>Account"</strong> section.<span style="font-family:Segoe UI">
				</span></span></p><p>
 </p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1426_AzureCustom44.png" alt="" /><span style="color:black;font-family:Segoe UI;font-size:9pt">
			</span></p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt">
 </p></p>]]></content:encoded>
    </item>
    <item>
      <title>Azure Custom Vison en action</title>
      <link>https://docs.microsoft.com/archive/blogs/franmer/azure-custom-vison-en-action</link>
      <pubDate>Fri, 17 Aug 2018 13:41:39 GMT</pubDate>
      <dc:creator><![CDATA[Franck Mercier]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/franmer/?p=12255</guid>
      <description><![CDATA[La plateforme Azure propose de nombreux services cognitifs prêts à l'emploi, permettant d'enrichir...]]></description>
      <content:encoded><![CDATA[<p>La plateforme Azure propose de nombreux services cognitifs prêts à l'emploi, permettant d'enrichir facilement vos applications avec des fonctionnalités innovantes. 
</p><p>Dans cet article, nous allons voir comment utiliser le service Custom Vision. Nous allons entrainer un modèle pour l'apprendre à reconnaitre certains types de manteaux. Nous testerons ensuite ce modèle et enfin nous verrons comment l'utiliser au sein d'une application.
</p><p>
 </p><h1>Prérequis
</h1><ul><li><a href="https://azure.microsoft.com/fr-fr/free/">Un compte Azure</a>
		</li><li><a href="https://visualstudio.microsoft.com/vs/whatsnew/">Visual Studio 2017</a>
		</li></ul><p>La partie concernant le notebook peut se faire, entre autres, avec :
</p><ul><li>Le Service <a href="https://notebooks.azure.com/">Microsoft Azure Notebooks</a>
		</li><li>La machine virtuelle « Data Science » proposée depuis le portail <a href="https://portal.azure.com">Azure </a>
		</li></ul><p>Dans cet article, nous allons utiliser la machine virtuelle « Data Science »,  
</p><h1>Création d'une machine virtuelle « Data Science »
</h1><ul><li>Connectez vous sur le portail Azure : <a href="https://portal.azure.com">https://portal.azure.com</a>
		</li><li>Cliquez sur « <strong>Create a resource</strong> », puis recherchez la machine virtuelle « Data Science »
</li></ul><p>
 </p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom1.png" alt="" />
	</p><p>Sélectionnez la machine « <strong>Data Science Virtual Machine for Linux (Ubuntu)</strong> » puis cliquez sur le bouton « <strong>Create</strong> »
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom2.png" alt="" />
	</p><p>
 </p><p>
 </p><p>Remplissez les informations de création de la machine virtuelle
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom3.png" alt="" />
	</p><p>A la fin du process cliquez sur le bouton « <strong>Create</strong> »
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom4.png" alt="" />
	</p><p>
 </p><p>Maintenant que la machine virtuelle est créée, nous allons nous connecter sur son server Jupyter. La connexion se fait avec une URL de type :
</p><p><a>https://&lt;Your_VM_IPAddress&gt;:8000</a>
	</p><p>Dans le cas de mon exemple cette adresse sera :
</p><p><a href="https://40.86.210.115:8000">https://40.86.210.115:8000</a>
	</p><p>
 </p><p>L'adresse IP de la machine se trouve sur le portail Azure :
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom5.png" alt="" />
	</p><p>
 </p><p>Il se peut que la fenêtre suivante s'affiche. Cliquez sur « <strong>Details</strong> » puis sur « <strong>Go on the web page</strong> » 
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom6.png" alt="" />
	</p><p>
 </p><p>Dans la fenêtre de connexion, entrez le nom et le mot de passe que vous avez utilisés lors de la création de la machine virtuelle :
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom7.png" alt="" />
	</p><p>Après quelques secondes, vous devez arriver sur la page d'accueil du serveur Jupyter. 
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom8.png" alt="" />
	</p><p>Nous allons créer un dossier pour faciliter notre travail. Cliquez sur « <strong>New</strong> » puis sur « <strong>Folder</strong> »
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom9.png" alt="" />
	</p><p>
 </p><p>Cochez la case à gauche du dossier nouvellement créé (le dossier se nomme « <em>Untitled Folder »), </em>puis cliquez sur le bouton « <strong>rename</strong> » un haut de la page.
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom10.png" alt="" />
	</p><p>Renommez le dossier puis cliquez sur le bouton « <strong>Rename</strong> »
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom11.png" alt="" />
	</p><p>
 </p><p>
 </p><h1>Création du notebook
</h1><p>Entrez dans le dossier précédemment créé. Cliquez sur le bouton « <strong><em>New</em></strong> » puis sur « <strong><em>Python 3</em></strong> »   
</p><p>
 </p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom12.png" alt="" />
	</p><p>Une fois le <em>Notebook</em> créé, cliquez sur « <strong>Untitled</strong> » et donnez-lui un nom. Cliquez sur « <strong>Rename</strong> »
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom13.png" alt="" />
	</p><p>
 </p><h2>Téléchargement des images
</h2><p>Dans la première cellule du Notebook, copiez le code ci-dessous pour récupérer les images d'entrainements et de tests.
</p><p>! curl -O <a href="https://canadastore.blob.core.windows.net/franmerpictures/Pictures.zip">https://canadastore.blob.core.windows.net/franmerpictures/Pictures.zip</a>
	</p><p>Puis cliquez sur « <strong>Run</strong> » dans la barre d'outils (ou utilisez la combinaison de touche « <strong><em>Shift Enter</em></strong> » ou « <strong><em>Ctrl Enter</em></strong> »). Pour le reste de l'article, après avoir copié le code dans les cellules, pensez bien à exécuter le code
</p><p>
		<img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom14.png" alt="" />
	</p><p>Si tout se passe bien, le fichier Pictures.zip doit apparaître dans votre dossier
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom15.png" alt="" />
	</p><p>Nous allons maintenant décompresser le fichier. Utilisez la commande-ci-dessous :
</p><p>!  unzip Pictures.zip
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom16.png" alt="" />
	</p><p>
 </p><p>
 </p><p><strong>Attention</strong> : l'astérisque présent entre les crochets, signifie que le code est en cours d'exécution. Il est de bon aloi d'attendre qu'il disparaisse avant d'exécuter le code d'une autre cellule.
</p><p style="text-align: center"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom17.png" alt="" />
	</p><p>
 </p><p>
 </p><p>Trois nouveaux dossiers ont dû apparaître :
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom18.png" alt="" />
	</p><h2>Affichage d'une image
</h2><p>Nous allons afficher une image et de voir comment faire des manipulations simples avec. Nous allons utiliser la librairie « <em>matplotlib</em> ». La documentation détaillée de cette librairie se trouve ici : <a href="https://matplotlib.org/">https://matplotlib.org/</a>.
</p><p>Copiez le code ci-dessous dans une nouvelle cellule :
</p><p style="margin-left: 36pt">#<em>Afficher une image / Display a picture</em>
	</p><p style="margin-left: 36pt"># <em>Importation de librairie matplotlib / Import the matplotlib libraries</em>
	</p><p style="margin-left: 36pt">import matplotlib.pyplot as plt
</p><p style="margin-left: 36pt">import matplotlib.image as im
</p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt">img = im.imread('hardshell_jackets/10116634x1038116_zm.jpeg')
</p><p style="margin-left: 36pt">imgplot = plt.imshow(img)
</p><p style="margin-left: 36pt">
 </p><p>Il se peut que lors de la première exécution, le message ci-dessous apparaît. Cela n'aura aucune incidence sur la suite des résultats.
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom19.png" alt="" />
	</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom20.png" alt="" />
	</p><h2>Récupérer des informations de l'image
</h2><p>Une image est intrinsèquement un tableau de valeurs de <a href="https://en.wikipedia.org/wiki/Pixel">pixels</a> (picture element) et il est important de pouvoir récupérer certaines informations concernant une image, afin de pouvoir les utiliser avec des algorithmes de reconnaissance d'objet. Ci-dessous, un exemple de code permettant de récupérer certaines informations.
</p><p style="margin-left: 36pt">#<em>Information sur l'image / Picture's information</em>
	</p><p style="margin-left: 36pt">print ("Picture Shape: ")
</p><p style="margin-left: 36pt">print(img.shape)
</p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt">#<em>Total number of pixels is accessed by img.size:</em>
	</p><p style="margin-left: 36pt">print ("Number of pixels: ")
</p><p style="margin-left: 36pt">print (img.size)
</p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt">#<em>Image datatype is obtained by img.dtype:</em>
	</p><p style="margin-left: 36pt">print("Picture data type:")
</p><p style="margin-left: 36pt">print(img.dtype)
</p><p>
 </p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom21.png" alt="" />
	</p><p>
 </p><h1>Intégration avec le service cognitif « Custom Vision »
</h1><p>Microsoft propose de nombreux services cognitifs dont la liste complète est disponible via le lien suivant : <a href="https://azure.microsoft.com/en-us/services/cognitive-services/directory/">https://azure.microsoft.com/en-us/services/cognitive-services/directory/</a>
	</p><p>De plus, ces services peuvent être appelés en tant que service web afin de retourner les résultats d'une prédiction. 
</p><p>Dans cet exemple, nous allons utiliser le service « <strong>Custom Vision</strong> ». Ce service est disponible via le lien suivant : <a href="https://customvision.ai/">https://customvision.ai/</a>.
</p><p>Mais avant, il nous reste des petites préparations à faire au niveau de notre Notebook.
</p><h2>Installation du SDK Custom Vision
</h2><p>Dans un premier temps nous allons vérifier la présence de « pip » et de sa mise à jour. « pip » est un outil permettant l'installation de packages Python. Dans une nouvelle cellule du Notebook, copiez le code suivant :
</p><p style="margin-left: 36pt">#<em>installation de pip / pip installation</em>
	</p><p style="margin-left: 36pt">import sys
</p><p style="margin-left: 36pt">! {sys.executable} -m pip freeze
</p><p style="margin-left: 36pt">! {sys.executable} -m pip --version
</p><p style="margin-left: 36pt">! {sys.executable} -m pip install --upgrade pip
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom22.png" alt="" />
	</p><p>
 </p><p>
 </p><p>Depuis votre notebook, entrez la commande suivante : (nous utilisons donc « pip » pour installer le package du service cognitif « Custom vision ») :
</p><p>#Installation du SDK Custom Vision / Install the Custom Vision SDK
</p><p>! {sys.executable} -m pip install azure-cognitiveservices-vision-customvision
</p><p>
 </p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom23.png" alt="" />
	</p><p>
 </p><p> 
 </p><h2>Configuration du service cognitif « Custom Vision »
</h2><p>Nous allons maintenant créer un service « Custom vision » en suivant le lien suivant :
</p><p><a href="https://customvision.ai">https://customvision.ai</a>
	</p><p>Une fois sur la page d'accueil, cliquez sur « <strong>Sign in</strong> »
</p><p>
 </p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom24.png" alt="" />
	</p><p>Vous avez la possibilité de tester gratuitement nos services cognitifs. Vous pouvez choisir de cliquer sur « Continue with trial » ou cliquez sur « Sign up for Azure ». Pour notre exemple, nous allons choisir « <strong>Continue with trial</strong> » :
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom25.png" alt="" />
	</p><p>Une fois le service créé, récupérez les informations de votre service en cliquant sur l'engrenage en haut à droite de la fenêtre
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom26.png" alt="" />
	</p><p>Puis récupérez les valeurs de vos clefs 
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom27.png" alt="" />
	</p><p>Revenez dans votre Notebook Jupyter pour y assigner les valeurs de vos clefs dans les 2 variables ci-dessous et exécutez le code :
</p><p style="margin-left: 36pt"># Assignez les clefs de votre service "Custom Vision" aux variables / Assign your Custom service keys to variables
</p><p style="margin-left: 36pt">training_key = 'c5926d0852854f459c85facff519c759'
</p><p style="margin-left: 36pt">prediction_key = '32446a7de71b496798d38fded67fc2da'
</p><p style="margin-left: 36pt">
 </p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom28.png" alt="" />
	</p><p>
 </p><h2>Création d'un projet Custom Vision
</h2><p>A partir du Notebook, nous allons créer un projet dans le service cognitif « Custom Vision ». Dans une nouvelle cellule, copiez le code ci-dessous et exécutez-le :
</p><p style="margin-left: 36pt">from azure.cognitiveservices.vision.customvision.training import training_api
</p><p style="margin-left: 36pt">from azure.cognitiveservices.vision.customvision.training.models import ImageUrlCreateEntry
</p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt">trainer = training_api.TrainingApi(training_key)
</p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt"># Create a new project
</p><p style="margin-left: 36pt">print ("Creating project...")
</p><p style="margin-left: 36pt">project = trainer.create_project("MyProject")
</p><p>
 </p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom29.png" alt="" />
	</p><p>
 </p><p>Si vous retournez sur l'interface web du « Custom Vison » service, vous devez y trouver un nouveau projet :
</p><p style="text-align: center"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom30.png" alt="" />
	</p><p>
 </p><h2>Création des labels
</h2><p>Avant d'ajouter des images dans le service, nous allons créer nos premiers labels afin d'identifier les images.
</p><p>Ajoutez le code suivant dans une nouvelle cellule et exécutez le code :
</p><p style="margin-left: 36pt"># <em>Création des labels les images / Add tags for pictures</em>
	</p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt">print("Creating tags")
</p><p style="margin-left: 36pt">hardshell_tag = trainer.create_tag(project.id,"Hardshell")
</p><p style="margin-left: 36pt">insulated_tag = trainer.create_tag(project.id,"Insulated")
</p><p style="margin-left: 36pt">print("Tags created")
</p><p>
 </p><p style="text-align: center"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom31.png" alt="" />
	</p><p>
 </p><h2>Chargement des images
</h2><p>Maintenant nous allons importer les images dans notre projet « Custom Vision » et ajouter les labels en même temps. Copiez et exécutez le code ci-dessous dans une nouvelle cellule :
</p><p style="margin-left: 36pt"># Téléchargez les images / Upload pictures
</p><p style="margin-left: 36pt">import os
</p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt">print("Adding hardshell images...")
</p><p style="margin-left: 36pt">hardshell_folder = "jacket_images/hardshell_jackets"
</p><p style="margin-left: 36pt">for file in os.listdir(os.fsencode("jacket_images/hardshell_jackets")):
</p><p style="margin-left: 36pt">    with open(hardshell_folder + "/" + os.fsdecode(file),mode="rb") as Hardshell_img_data:
</p><p style="margin-left: 36pt">        trainer.create_images_from_data(project.id,Hardshell_img_data,[hardshell_tag.id])
</p><p style="margin-left: 36pt">        
 </p><p style="margin-left: 36pt">print("Adding insulated images...")
</p><p style="margin-left: 36pt">insulated_folder = "jacket_images/insulated_jackets"
</p><p style="margin-left: 36pt">for file2 in os.listdir(os.fsencode("jacket_images/insulated_jackets")):
</p><p style="margin-left: 36pt">    with open(insulated_folder + "/" + os.fsdecode(file2),mode="rb") as insulated_img_data:
</p><p style="margin-left: 36pt">        trainer.create_images_from_data(project.id,insulated_img_data,[insulated_tag.id])
</p><p style="margin-left: 36pt">        
 </p><p style="margin-left: 36pt">print("Done !")
</p><p>
 </p><p style="text-align: center;margin-left: 36pt"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom32.png" alt="" />
	</p><p style="text-align: center;margin-left: 36pt">
 </p><p style="text-align: center;margin-left: 36pt">
 </p><p style="margin-left: 36pt">Vérifier la présence des images dans l'interface web du service cognitif et que les images possèdent le bon label.
</p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom33.png" alt="" />
	</p><p>
 </p><p>
 </p><p>
 </p><p>
 </p><p>
 </p><h1>Entrainement du projet
</h1><p>Après avoir ajouté les images et défini les différents labels, nous pouvons maintenant entrainer un model permettant d'identifier nos images.
</p><p>Dans une nouvelle cellule, copiez et exécutez le code ci-dessous :
</p><p style="margin-left: 36pt"><em>#Entrainement du projet / Train the project
</em></p><p style="margin-left: 36pt"><em>import time
</em></p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt"><em>print("Training....")
</em></p><p style="margin-left: 36pt"><em>iteration = trainer.train_project(project.id)
</em></p><p style="margin-left: 36pt"><em>print (iteration.status)
</em></p><p style="margin-left: 36pt"><em>while (iteration.status != "Completed"):
</em></p><p style="margin-left: 36pt"><em>    iteration = trainer.get_iteration(project.id,iteration.id)
</em></p><p style="margin-left: 36pt"><em>    print("Training status: " + iteration.status)
</em></p><p style="margin-left: 36pt"><em>    time.sleep(1)
</em></p><p style="margin-left: 36pt">    
 </p><p style="margin-left: 36pt"><em># Set this iteration of the project as the default.
</em></p><p style="margin-left: 36pt"><em>trainer.update_iteration(project.id,iteration.id,is_default=True)
</em></p><p style="margin-left: 36pt"><em>print("Done!")
</em></p><p style="margin-left: 36pt">
 </p><p style="text-align: center"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom34.png" alt="" />
	</p><p>
 </p><p>
 </p><p>Si on vérifie dans l'interface web du service cognitif, une première itération de notre model a été créée.
</p><p style="text-align: center"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom35.png" alt="" />
	</p><p style="text-align: center">
 </p><p>
 </p><h1>Test du model
</h1><p>Maintenant que le modèle a été entrainé, nous allons le tester avec un autre set d'images
</p><p>Dans un premier temps, nous allons créer une fonction pour convertir les images et envoyer une valeur de données au point de terminaison du service cognitif.
</p><p>Pour faire cette conversion, nous allons créer une fonction. Copiez le code ci-dessous dans une nouvelle cellule :
</p><p>
 </p><p style="margin-left: 36pt">def read_image_data(img_path):
</p><p style="margin-left: 36pt">    import numpy as np
</p><p style="margin-left: 36pt">    from io import BytesIO
</p><p style="margin-left: 36pt">    import matplotlib.pyplot as plt
</p><p style="margin-left: 36pt">    
 </p><p style="margin-left: 36pt">    # Load the numpy array
</p><p style="margin-left: 36pt">    #imgArray = np.load(img_path)
</p><p style="margin-left: 36pt">    imgArray = im.imread(img_path)
</p><p style="margin-left: 36pt">    # Write the array data to a stream
</p><p style="margin-left: 36pt">    imageStream = BytesIO()
</p><p style="margin-left: 36pt">    plt.imsave(imageStream, imgArray)
</p><p style="margin-left: 36pt">    # Read the stream from the beginning
</p><p style="margin-left: 36pt">    imageStream.seek(0)
</p><p style="margin-left: 36pt">    return imageStream.read()
</p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt">print ('read_image_data function created!')
</p><p>
 </p><p style="text-align: center"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom36.png" alt="" />
	</p><p>
 </p><p>
 </p><p>Nous allons utiliser le modèle que nous avons entrainer pour réaliser des prédictions sur des images de tests. Nous allons aussi utiliser la fonction créée précédemment pour convertir les images avant de les envoyer au modèle.
</p><p>Dans une nouvelle cellule de votre Notebook, copiez le code ci-dessous :
</p><p style="margin-left: 36pt"><span style="font-size:9pt">import os
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">import time
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">import numpy as np 
</span></p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt"><span style="font-size:9pt">#Importation du point de terminaison de prédiction / Import the prediction endpoint
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">from azure.cognitiveservices.vision.customvision.prediction import prediction_endpoint
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">from azure.cognitiveservices.vision.customvision.prediction.prediction_endpoint import models
</span></p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt"><span style="font-size:9pt">#Création d'une instance du point de terminaison de prédiction
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">#Create an instance of the prediction endpoint 
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">predictor = prediction_endpoint.PredictionEndpoint(prediction_key)
</span></p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt"><span style="font-size:9pt">#Boucle sur l'ensemble des images / Loop through the test images
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">folder = 'Test'
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">files = os.listdir(folder)
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">i=1
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">x = np.linspace(0,10)
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">y = np.sin(x)
</span></p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt"><span style="font-size:9pt">for file in sorted(files):
</span></p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt"><span style="font-size:9pt">    #Les images sont traitées dans l'ordre / process files in order
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">    #Récupération du chemin de l'image et lecture des données / Get the file path and read the image data
</span></p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt"><span style="font-size:9pt">    img_path = os.path.join(folder,file) #Test pour savoir si c'est un fichier ou un dossier        
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">    if os.path.isfile(img_path):
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">        print("File name: " + file)  
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">        img = im.imread(img_path)
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">        plt.imshow(img)
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">        plt.show()
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">        #plt.plot(x,y)
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">        #plt.figure(i+1)    
</span></p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt"><span style="font-size:9pt">        img_data = read_image_data(img_path)  
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">        #Récupération des prédictions pour les images / Get the predicted tags for the image
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">        results = predictor.predict_image(project.id, img_data, iteration.id)
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">        fig = plt.figure()
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">        #Affichage des labels et des probabilités / Display the tag name and probability for each prediction
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">        for prediction in results.predictions: 
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">            print ("\t" + prediction.tag_name + ": {0:.2f}%".format(prediction.probability * 100))
</span></p><p style="margin-left: 36pt">            
 </p><p style="margin-left: 36pt"><span style="font-size:9pt">         print('\n')
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">        #Pause technique :) / Technical Delay
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">        time.sleep(0.25)
</span></p><p style="margin-left: 36pt"><span style="font-size:9pt">        i=i+1
</span></p><p>
 </p><p style="text-align: justify;margin-left: 18pt"><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom37.png" alt="" />
	</p><p>
 </p><p style="margin-left: 36pt">Notre model nous retourne donc des prédictions sur les images afin de tenter d'identifier si les images analysées sont des manteaux ou non, et si oui, quel type de manteau. Ci-dessous des exemples avec des images de tests
<div style="margin-left: 36pt"><table style="border-collapse:collapse" border="0"><colgroup><col style="width:384px" /><col style="width:384px" /><col style="width:384px" /></colgroup><tbody valign="top"><tr><td style="padding-left: 14px;padding-right: 14px"> </td><td style="padding-left: 14px;padding-right: 14px"> </td><td style="padding-left: 14px;padding-right: 14px"> </td></tr></tbody></table></div><p style="margin-left: 36pt">
 </p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom38.png" alt="" />
		</p><h1>Utilisation du service cognitif avec Visual Studio
</h1><p style="margin-left: 36pt">
 </p><p>Maintenant que notre modèle fonction, il est peut-être aussi intéressant d'utiliser l'API du service cognitif afin d'intégrer les prédictions dans une application. Ci-dessous, une illustration rapide d'intégration du service cognitif dans une application.
</p><p>
 </p><p>Démarrez Visual Studio 2017 et créez un projet de type « Console App ».
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom39.png" alt="" />
		</p><p>
 </p><p>Une fois le projet créé, dans le menu « <strong>Tools</strong> / <strong>NuGet Package Manager</strong> / <strong>Manage NuGet Packages for solution</strong>… » de Visual studio, et ajoutez les packages du Custom Vision comme illustré ci-dessous :
</p><p>
 </p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom40.png" alt="" />
		</p><p>
 </p><p>
 </p><p>Rajoutez les 2 packages suivants :
</p><p>
 </p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom41.png" alt="" />
		</p><p>
 </p><p>Puis dans le fichier program.cs rajoutez le code ci-dessous. Remplacez les clefs par celles de votre projet du service cognitif
</p><p>
 </p><p style="margin-left: 36pt"><span style="color:blue;font-family:Consolas;font-size:9pt">using<span style="color:black"> Microsoft.Cognitive.CustomVision.Prediction;
</span></span></p><p style="margin-left: 36pt"><span style="color:blue;font-family:Consolas;font-size:9pt">using<span style="color:black"> Microsoft.Cognitive.CustomVision.Training;
</span></span></p><p style="margin-left: 36pt"><span style="color:blue;font-family:Consolas;font-size:9pt">using<span style="color:black"> Microsoft.Cognitive.CustomVision.Training.Models;
</span></span></p><p style="margin-left: 36pt"><span style="color:blue;font-family:Consolas;font-size:9pt">using<span style="color:black"> System;
</span></span></p><p style="margin-left: 36pt"><span style="color:blue;font-family:Consolas;font-size:9pt">using<span style="color:black"> System.Collections.Generic;
</span></span></p><p style="margin-left: 36pt"><span style="color:blue;font-family:Consolas;font-size:9pt">using<span style="color:black"> System.IO;
</span></span></p><p style="margin-left: 36pt"><span style="color:blue;font-family:Consolas;font-size:9pt">using<span style="color:black"> System.Linq;
</span></span></p><p style="margin-left: 36pt"><span style="color:blue;font-family:Consolas;font-size:9pt">using<span style="color:black"> System.Threading;
</span></span></p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt"><span style="color:blue;font-family:Consolas;font-size:9pt">namespace<span style="color:black"> myTutorialCustomVision
</span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">{
</span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">
				<span style="color:blue">class<span style="color:black">
						<span style="color:#2b91af">Program<span style="color:black">
							</span></span></span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">    {
</span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">
				<span style="color:green">//private static MemoryStream testImage;<span style="color:black">
					</span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">
				<span style="color:blue">static<span style="color:black">
						<span style="color:blue">void<span style="color:black"> Main(<span style="color:blue">string<span style="color:black">[] args)
</span></span></span></span></span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">        {
</span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">
				<span style="color:blue">var<span style="color:black"> projectID = <span style="color:#a31515">"&lt;YourProjectID&gt;"<span style="color:black">;
</span></span></span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">
				<span style="color:blue">var<span style="color:black"> trainingKey = <span style="color:#a31515">"&lt;YourTrainingKey&gt;"<span style="color:black">;
</span></span></span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">
				<span style="color:blue">var<span style="color:black"> predictionKey = <span style="color:#a31515">"&lt;YourPredictionKey&gt;"<span style="color:black">;
</span></span></span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">
				<span style="color:blue">string<span style="color:black"> imagesPath = <span style="color:maroon">@"..\..\..\myTutorialCustomVision\Images"<span style="color:black">;
</span></span></span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">
				<span style="color:blue">string<span style="color:black">[] imageFiles = Directory.GetFiles(imagesPath, <span style="color:#a31515">"*.jpg"<span style="color:black">);
</span></span></span></span></span></p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">            TrainingApi trainingApi = <span style="color:blue">new<span style="color:black"> TrainingApi() { ApiKey = trainingKey };
</span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">
				<span style="color:blue">var<span style="color:black"> project = trainingApi.GetProjects();
</span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">            Guid myGuid = project[0].Id;
</span></p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">
				<span style="color:blue">var<span style="color:black"> iterations = trainingApi.GetIterations(Guid.Parse(projectID));
</span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">
				<span style="color:blue">var<span style="color:black"> validIterations = iterations.Where(iter =&gt; iter.Status == <span style="color:#a31515">"Completed"<span style="color:black">);
</span></span></span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">
				<span style="color:blue">var<span style="color:black"> lastIterationTrained = validIterations.OrderBy(iter =&gt; iter.LastModified).Last();
</span></span></span></p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt">            
 </p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">            Iteration lastIteration = trainingApi.GetIteration(myGuid, lastIterationTrained.Id);
</span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">            lastIteration.IsDefault = <span style="color:blue">true<span style="color:black">;
</span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">            trainingApi.UpdateIteration(myGuid, lastIteration.Id, lastIteration);
</span></p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt">            
 </p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">
				<span style="color:blue">foreach<span style="color:black"> (var image <span style="color:blue">in<span style="color:black"> imageFiles)
</span></span></span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">            {
</span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">                FileStream fileStream = <span style="color:blue">new<span style="color:black"> FileStream(image, FileMode.Open, FileAccess.Read);
</span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">                PredictionEndpoint endpoint = <span style="color:blue">new<span style="color:black"> PredictionEndpoint() { ApiKey = predictionKey };
</span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">                Console.WriteLine(<span style="color:#a31515">"Making a prediction for picture: "<span style="color:black"> + Path.GetFileName(image));
</span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">
				<span style="color:blue">var<span style="color:black"> result = endpoint.PredictImage(myGuid, fileStream);
</span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">
				<span style="color:blue">foreach<span style="color:black"> (var c <span style="color:blue">in<span style="color:black"> result.Predictions)
</span></span></span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">                {
</span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">                    Console.WriteLine(<span style="color:#a31515">$"\t<span style="color:black">{c.Tag}<span style="color:#a31515">: <span style="color:black">{c.Probability:<span style="color:#a31515">P1<span style="color:black">}<span style="color:#a31515">"<span style="color:black">);
</span></span></span></span></span></span></span></span></span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">                }
</span></p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">            }
</span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">            Console.ReadKey();
</span></p><p style="margin-left: 36pt">            
 </p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">        }
</span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">    }
</span></p><p style="margin-left: 36pt"><span style="color:black;font-family:Consolas;font-size:9pt">}
</span></p><p>
 </p><p>
 </p><h2>Test de l'application
</h2><p>Pour tester l'application et les prédictions, j'ai rajouté un dossier Images dans le « Solution Explorer » et j'ai copié 2 images dans ce dossier
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom42.png" alt="" />
		</p><p>
 </p><p>
 </p><p>
 </p><h2>Résultat
</h2><p>L'application va retourner, pour chacune des images, une prédiction pour chacun des labels.  
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom43.png" alt="" />
		</p><p>
 </p><p><span style="color:black;font-family:Segoe UI;font-size:9pt">Il se peut que vous obteniez l'erreur « Operation returned an invalid status code '429' » si vous réalisez le test avec une grande quantité d'images. Souvent cette erreur vient du fait que votre service est soit en version d'essai soit sous-dimensionné. Pour corriger le problème, il suffit juste de changer le « Pricing tier » dans la page web du service custom vision, dans la partie « <strong>Account</strong> », 
</span></p><p>
 </p><p><img src="https://msdnshared.blob.core.windows.net/media/2018/08/081718_1417_AzureCustom44.png" alt="" /><span style="color:black;font-family:Segoe UI;font-size:9pt">
			</span></p><p style="margin-left: 36pt">
 </p><p style="margin-left: 36pt">
 </p></p>]]></content:encoded>
    </item>
    <item>
      <title>Microsoft Azure Databricks (English version)</title>
      <link>https://docs.microsoft.com/archive/blogs/franmer/microsoft-azure-databricks-english-version</link>
      <pubDate>Mon, 09 Apr 2018 17:12:04 GMT</pubDate>
      <dc:creator><![CDATA[Franck Mercier]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/franmer/?p=11805</guid>
      <description><![CDATA[During the datavore 2018 event in Montreal, we delivered a workshop on Azure Databrick. I had to...]]></description>
      <content:encoded><![CDATA[During the datavore 2018 event in Montreal, we delivered a workshop on Azure Databrick. I had to prepare the data preparation and Engineering part of the workshop. In this article I share the content we used during this workshop.
<h2>Presentation of Azure Databricks</h2>
Databricks is our new collaborative Big Data and Machine Learning platform. This new first-class Azure service is an Apache Spark-based analytics platform optimized for Azure. Azure Databricks comprises the complete open-source Apache Spark cluster technologies and capabilities. Workloads like artificial intelligence, predictive analytics or real-time analysis can be easily and securely handle by Azure Databricks.

This article consists of two major parts
<ul>
 	<li><strong>Part 1</strong>: Setting up the Azure environment</li>
 	<li>
<div><strong>Part 2</strong>: Using Databricks</div>
<ul>
 	<li>Workshop: Data Engineering with Databricks</li>
</ul>
</li>
</ul>
<h1>Part 1: Azure configuration</h1>
<h2>Resource Group creation</h2>
A resource group is a logical grouping of your resources in Azure to facilitate its management. All Azure resources must belong to a resource group.

First, you need to connect to the Azure portal: <a href="https://portal.azure.com">Https://portal.azure.com</a>

From the Azure portal, click « <strong>Resource groups</strong> » and then click « <strong>Add</strong> »

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz1.png" />

Fill in the information of your resource group.

For this lab, choose the region "<strong>East US 2". </strong>Click on "<strong>Create"
</strong>

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz2.png" />

Once the resource group is created, a notification appears at the top right of the screen. Click on " <strong>Go to Resource Group</strong> ».

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz3.png" />

Your resource group is created and ready to be used.

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz4.png" />
<h2>Create an Azure Storage Account</h2>
An Azure Storage Account is a cloud service that provides highly available, secure, durable, scalable, and redundant storage. Azure storage consists of storage of BLOB objects, file storage, and queue storage. For our Lab, we will use the storage of BLOB objects. For more information about Azure storage, you can view this article: <a href="https://docs.microsoft.com/fr-fr/azure/storage/">https://docs.microsoft.com/fr-fr/azure/storage/</a>

To have a quick overview, a storage account can contain one or more containers that themselves will contain BLOBs (folders and files)

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz5.png" />

The storage account can be created in the same way as we did for resource group through the portal. But it is also possible to use the « <em>Cloud Shell</em> », natively integrated to the portal. That's what we're going to do below.

At the top of the Azure portal, click the "<em>Cloud Shell</em>" icon.

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz6.png" />

The « <em>Cloud Shell</em> » will open at the bottom of the screen. Click on "<strong>Bash (Linux</strong>)"

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz7.png" />

If this is the first time you run the "<em>Cloud Shell</em>", the next window will appear. Choose your Azure subscription, and then click "<strong>Create storage</strong>".

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz8.png" />

Once set, the "<em>Cloud Shell"</em> is ready to be used.

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz9.png" />

The creation of a storage account can be done with the following command:

<span style="color: #0101fd;font-family: Consolas;font-size: 10pt">az storage account </span><span style="color: #0101fd;font-family: Consolas;font-size: 10pt">create </span><span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--name </span><span style="background-color: yellow">&lt;yourStorageAccount&gt; </span><span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--resource-group </span><span style="background-color: yellow"><strong>&lt;yourResourceGroup&gt;  </strong></span><span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--location</span> eastus2 <span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--sku</span> Standard_LRS

In the case of this example, here is the corresponding command line:

<span style="color: #0101fd;font-family: Consolas;font-size: 10pt">az storage account create<span style="color: #001000;font-family: Georgia;font-size: medium"> </span></span><span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--name</span> datavorestorage <span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--resource-group</span> datavore <span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--location</span> eastus2 <span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--sku</span> Standard_LRS

After few seconds, the storage account is created. Click on the "<strong>Refresh"</strong> button of your resource group. Your storage account should then appears in your resource group.

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz11.png" />

If you click on your account storage, you will then access to the various functions and properties of the storage account. In particular, the information connection by clicking on « <strong>Access Key</strong> ».

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz12.png" />

Now that the storage account is available, we'll create the containers to store our different files.

Before creating the containers, you must be able to access the storage account. To do this, you have to get your account key. Below is a command to retrieve your keys (you can also retrieve your keys through the portal as shown above).

<span style="color: #0101fd;font-family: Consolas;font-size: 10pt">az storage account keys list </span><span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--account-name </span><span style="background-color: yellow">&lt;yourStorageAccount &gt; </span><span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--resource-group </span><span style="background-color: yellow">&lt;yourResourceGroup&gt; </span><span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--output </span><span style="color: #0101fd;font-family: Consolas;font-size: 10pt">table</span>

In our example, here is the command used:

<span style="color: #0101fd;font-family: Consolas;font-size: 10pt">az storage account keys list </span><span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--account-name</span> datavorestorage <span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--resource-group</span> datavore <span style="color: #007d9a"><span style="font-family: Consolas;font-size: 10pt">--output <span style="color: #0101fd">table</span></span>
<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz13.png" /></span>

Copy one of the two keys. Then export the information from your storage account with the following commands:

<span style="color: #0101fd;font-family: Consolas;font-size: 10pt">export</span> AZURE_STORAGE_ACCOUNT="<span style="background-color: yellow">&lt;YourStorageAccount&gt;</span>"

<span style="color: #0101fd;font-family: Consolas;font-size: 10pt">export</span> AZURE_STORAGE_ACCESS_KEY="<span style="background-color: yellow">&lt;YourKey&gt;</span>"

Here are the command lines About our workshop:

<span style="color: #0101fd;font-family: Consolas;font-size: 10pt">export</span> AZURE_STORAGE_ACCOUNT="datavorestorage"

<span style="color: #0101fd;font-family: Consolas;font-size: 10pt">export</span> AZURE_STORAGE_ACCESS_KEY=" yqwBdGRgCW0LWdEuRwGdnxKPit+zXNrrVOxXQy57wq6oHmCSy2NnoA3Pr9E4pMgJPwcVeg8uQt1Uzk5YAWntiw=="
<h3>Containers Creations</h3>
To create the containers, copy the below scripts in your Cloud Shell

<span style="color: #0101fd;font-family: Consolas;font-size: 10pt">az s<span style="color: black"><span style="color: #0101fd">torage <span style="color: black"><span style="color: #0101fd">container <span style="color: black"><span style="color: #0101fd">create<span style="color: #007d9a"> --name<span style="color: black"><span style="background-color: #f9f9f9"> nyctaxi-consumption
</span><span style="color: #0101fd">az <span style="color: black"><span style="color: #0101fd">storage <span style="color: black"><span style="color: #0101fd">container <span style="color: black"><span style="color: #0101fd">create<span style="color: #007d9a"> --name<span style="color: black"><span style="background-color: #f9f9f9"> nyctaxi-curated
</span><span style="color: #0101fd">az <span style="color: black"><span style="color: #0101fd">storage <span style="color: black"><span style="color: #0101fd">container <span style="color: black"><span style="color: #0101fd">create<span style="color: #007d9a"> --name<span style="color: black"><span style="background-color: #f9f9f9"> nyctaxi-demo
</span><span style="color: #0101fd">az <span style="color: black"><span style="color: #0101fd">storage <span style="color: black"><span style="color: #0101fd">container <span style="color: black"><span style="color: #0101fd">create<span style="color: #007d9a"> --name<span style="color: black"><span style="background-color: #f9f9f9"> nyctaxi-raw
</span><span style="color: #0101fd">az <span style="color: black"><span style="color: #0101fd">storage <span style="color: black"><span style="color: #0101fd">container <span style="color: black"><span style="color: #0101fd">create<span style="color: #007d9a"> --name<span style="color: black"><span style="background-color: #f9f9f9"> nyctaxi-ref-data
</span><span style="color: #0101fd">az <span style="color: black"><span style="color: #0101fd">storage <span style="color: black"><span style="color: #0101fd">container <span style="color: black"><span style="color: #0101fd">create<span style="color: #007d9a"> --name<span style="color: black"><span style="background-color: #f9f9f9"> nyctaxi-staging
</span><span style="color: #0101fd">az <span style="color: black"><span style="color: #0101fd">storage <span style="color: black"><span style="color: #0101fd">container <span style="color: black"><span style="color: #0101fd">create<span style="color: #007d9a"> --name<span style="color: black;background-color: #f9f9f9"> nyctaxi-scratch
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz14.png" />

To verify the creation of your containers, from the Azure portal, click your Azure storage account

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz15.png" />

In "<strong>Overview</strong>" section, click « <strong>Blobs</strong> »

You must find the containers created previously

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz17.png" />
<h2>Copying files for the workshop</h2>
<h3>Reference data</h3>
The files are stored in one of our storage account. <span style="color: red"><strong>Do not change the key below!!</strong></span>

Run this script in the "<em>Cloud Shell</em> »

<span style="color: #0101fd;font-family: Consolas;font-size: 10pt">export <span style="color: black;background-color: #f9f9f9">SRC_STORAGE_ACCOUNT="franmerstore"
</span></span>

<span style="color: #0101fd;font-family: Consolas;font-size: 10pt">export <span style="color: black;background-color: #f9f9f9">SRC_STORAGE_ACCESS_KEY="<span style="color: red">eSSFOUVLg4gB3iSxuFVh/lDVoMeQHCqVj67xHdaYcPYoMSUqFuD+E2OeDhY4wRZCEF97nCRGOV0i7WJDyoOd7g==<span style="color: black">"
</span></span></span></span>

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz18.png" />

And then the following command:

<span style="color: #0101fd"><span style="font-family: Consolas;font-size: 10pt">azcopy <span style="color: #007d9a">--source</span></span> https://franmerstore.blob.core.windows.net/nyctaxi-staging/reference-data/ <span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--destination</span> https://datavorestorage.blob.core.windows.net/nyctaxi-staging/reference-data/ <span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--source-key </span>$SRC_STORAGE_ACCESS_KEY <span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--dest-key</span> $AZURE_STORAGE_ACCESS_KEY <span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--sync-copy --recursive
</span></span>

In our example, here is the command to run with the storage account used in this example:

<span style="color: #0101fd"><span style="font-family: Consolas;font-size: 10pt">azcopy <span style="color: #007d9a">--source</span></span> https://franmerstore.blob.core.windows.net/nyctaxi-staging/reference-data/ <span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--destination</span> https://datavorestorage.blob.core.windows.net/nyctaxi-staging/reference-data/ <span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--source-key </span>$SRC_STORAGE_ACCESS_KEY <span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--dest-key</span> $AZURE_STORAGE_ACCESS_KEY <span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--sync-copy --recursive
</span></span>
<h3>Copying transactional data</h3>
For this lab, let's just take a subset of the data. If you want to recover the whole dataset, refer to the index at the end of the document (this will take at least 2h).

For this lab, we will only work on the year 2017, but nothing will prevent you later to rerun the scripts by simply changing the year.

Here are the scripts to copy transactional data:

<span style="color: #0101fd;font-family: Consolas;font-size: 10pt">azcopy</span>
<span style="color: #007d9a">--source</span> https://franmerstore.blob.core.windows.net/nyctaxi-staging/transactional-data/year=<span style="color: red">2017</span>/ <span style="color: #007d9a">--destination</span> https://<span style="background-color: yellow">&lt;YourStorageAccount&gt;</span>.blob.core.windows.net/nyctaxi-staging/transactional-data/year=<span style="color: red">2017</span>/ <span style="color: #007d9a">--source-key</span> $SRC_STORAGE_ACCESS_KEY <span style="color: #007d9a">--dest-key</span> $AZURE_STORAGE_ACCESS_KEY <span style="color: #007d9a">--sync-copy</span>
<span style="color: #007d9a">--recursive</span>

In our example, so we'll have:

<span style="color: #0101fd;font-family: Consolas;font-size: 10pt">azcopy</span>
<span style="color: #007d9a">--source</span> https://franmerstore.blob.core.windows.net/nyctaxi-staging/transactional-data/year=<span style="color: red">2017</span>/ <span style="color: #007d9a">--destination</span> https://datavorestorage.blob.core.windows.net/nyctaxi-staging/transactional-data/year=<span style="color: red">2017</span>/ <span style="color: #007d9a">--source-key</span> $SRC_STORAGE_ACCESS_KEY <span style="color: #007d9a">--dest-key</span> $AZURE_STORAGE_ACCESS_KEY <span style="color: #007d9a">--sync-copy</span>
<span style="color: #007d9a">--recursive</span>

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz20.png" />

To verify the result of your copy, you can run the following command:

<span style="color: #0101fd;font-family: Consolas;font-size: 10pt">az storage blob list </span><span style="color: #007d9a">--container-name</span> nyctaxi-staging <span style="color: #007d9a">--output table</span>

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz21.png" />
<h2>Create an Azure SQL Database</h2>
From the Azure portal, click on « <strong>+ Create a resource</strong> », « <strong>Databases</strong> » and then on « <strong>SQL Database</strong> »

Then fill in the values for your database
<ul>
 	<li>You may need to create a SQL server.</li>
 	<li>Click on « <strong>Configure required settings </strong>», « <strong>Create a new server</strong> ».</li>
 	<li>Fill in the SQL server information. <strong>Remember your SQL Server password!
</strong></li>
 	<li>Click on " <strong>Select</strong> ».</li>
</ul>
<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz23.png" />

Continue to fill in your database information. Then click on « <strong>Create</strong> »
<h2>Create SQL tables</h2>
From the Azure portal, click on your newly created database.

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz25.png" />

Click on « <strong>Query Editor</strong> », then « <strong>Login</strong> »

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz26.png" />

Enter your SQL credentials, and then click "<strong>Ok</strong>".

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz27.png" />
<h2>Create tables</h2>
From the Azure portal, copy the T-SQL script below to the editor, then click on "<strong>Run</strong>"
<p style="background: #fffffe"><span style="color: blue;font-size: 10pt">Drop <span style="color: black"><span style="color: blue">Table <span style="color: black"><span style="color: blue">If<span style="color: black"> exists TRIPS_BY_YEAR;<span style="font-family: Consolas">
</span></span></span></span></span></span></span></p>
<p style="background: #fffffe"><span style="color: blue;font-size: 10pt">Create <span style="color: black"><span style="color: blue">Table<span style="color: black"> TRIPS_BY_YEAR (<span style="font-family: Consolas">
</span></span></span></span></span></p>
<p style="background: #fffffe"><span style="color: black;font-size: 10pt">TAXI_TYPE <span style="color: blue">varchar<span style="color: black">(<span style="color: #09885a">10<span style="color: black">),<span style="font-family: Consolas">
</span></span></span></span></span></span></p>
<p style="background: #fffffe"><span style="color: black;font-size: 10pt">TRIP_YEAR <span style="color: blue">int<span style="color: black">,<span style="font-family: Consolas">
</span></span></span></span></p>
<p style="background: #fffffe"><span style="color: black;font-size: 10pt">TRIP_COUNT <span style="color: blue">bigint<span style="color: black;font-family: Consolas">
</span></span></span></p>
<p style="background: #fffffe"><span style="color: black;font-size: 10pt">);<span style="font-family: Consolas">
</span></span></p>
<p style="background: #fffffe"><img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz28.png" /><span style="color: black;font-family: Consolas;font-size: 10pt">
</span></p>
<p style="background: #fffffe">Repeat the operations for the following two tables</p>
<p style="background: #fffffe"><span style="color: blue;font-size: 10pt">Drop <span style="color: black"><span style="color: blue">Table <span style="color: black"><span style="color: blue">If<span style="color: black"> exists TRIPS_BY_HOUR;<span style="font-family: Consolas">
</span></span></span></span></span></span></span></p>
<p style="background: #fffffe"><span style="color: blue;font-size: 10pt">Create <span style="color: black"><span style="color: blue">Table<span style="color: black"> TRIPS_BY_HOUR (<span style="font-family: Consolas">
</span></span></span></span></span></p>
<p style="background: #fffffe"><span style="color: black;font-size: 10pt">TAXI_TYPE <span style="color: blue">varchar<span style="color: black">(<span style="color: #09885a">10<span style="color: black">),<span style="font-family: Consolas">
</span></span></span></span></span></span></p>
<p style="background: #fffffe"><span style="color: black;font-size: 10pt">TRIP_YEAR <span style="color: blue">int<span style="color: black">,<span style="font-family: Consolas">
</span></span></span></span></p>
<p style="background: #fffffe"><span style="color: black;font-size: 10pt">TRIP_HOUR INT,<span style="font-family: Consolas">
</span></span></p>
<p style="background: #fffffe"><span style="color: black;font-size: 10pt">TRIP_COUNT <span style="color: blue">bigint<span style="color: black;font-family: Consolas">
</span></span></span></p>
<p style="background: #fffffe"><span style="color: black;font-size: 10pt">);<span style="font-family: Consolas">
</span></span></p>
<p style="background: #fffffe"><span style="color: blue;font-size: 10pt">Drop <span style="color: black"><span style="color: blue">Table <span style="color: black"><span style="color: blue">If<span style="color: black"> exists BATCH_JOB_HISTORY;<span style="font-family: Consolas">
</span></span></span></span></span></span></span></p>
<p style="background: #fffffe"><span style="color: blue;font-size: 10pt">Create <span style="color: black"><span style="color: blue">Table<span style="color: black"> BATCH_JOB_HISTORY<span style="font-family: Consolas">
</span></span></span></span></span></p>
<p style="background: #fffffe"><span style="color: black;font-size: 10pt">(<span style="font-family: Consolas">
</span></span></p>
<p style="background: #fffffe"><span style="color: black;font-size: 10pt">batch_id <span style="color: blue">int<span style="color: black">,<span style="font-family: Consolas">
</span></span></span></span></p>
<p style="background: #fffffe"><span style="color: black;font-size: 10pt">batch_step_id <span style="color: blue">int<span style="color: black">,<span style="font-family: Consolas">
</span></span></span></span></p>
<p style="background: #fffffe"><span style="color: black;font-size: 10pt">Batch_step_description <span style="color: blue">varchar<span style="color: black">(<span style="color: #09885a">50<span style="color: black">),<span style="font-family: Consolas">
</span></span></span></span></span></span></p>
<p style="background: #fffffe"><span style="color: black;font-size: 10pt">Batch_step_status <span style="color: blue">varchar<span style="color: black">(<span style="color: #09885a">10<span style="color: black">),<span style="font-family: Consolas">
</span></span></span></span></span></span></p>
<p style="background: #fffffe"><span style="color: black;font-size: 10pt">Batch_step_time <span style="color: blue">varchar<span style="color: black">(<span style="color: #09885a">25<span style="color: black">)<span style="font-family: Consolas">
</span></span></span></span></span></span></p>
<p style="background: #fffffe"><span style="color: black;font-size: 10pt">);<span style="font-family: Consolas">
</span></span></p>
<p style="background: #fffffe"><span style="color: blue;font-size: 10pt">Alter <span style="color: black"><span style="color: blue">Table<span style="color: black"> BATCH_JOB_HISTORY<span style="font-family: Consolas">
</span></span></span></span></span></p>
<p style="background: #fffffe"><span style="color: blue;font-size: 10pt">Add <span style="color: black"><span style="color: blue">Constraint<span style="color: black"> Batch_step_time_def<span style="font-family: Consolas">
</span></span></span></span></span></p>
<p style="background: #fffffe"><span style="color: blue;font-size: 10pt">Default<span style="color: black"> CURRENT_TIMESTAMP <span style="color: blue">For<span style="color: black"> Batch_step_time; <span style="font-family: Consolas">
</span></span></span></span></span></p>
<p style="background: #fffffe"><span style="color: black;font-size: 10pt">You will see your tables from the Azure portal<span style="font-family: Consolas">
</span></span></p>
<p style="background: #fffffe"><img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz29.png" /><span style="color: black;font-family: Consolas;font-size: 10pt">
</span></p>

<h2>Create Azure Databricks</h2>
From the Azure portal, click on « <strong>+ Create a Resource</strong> », « <strong>Data + Analytics</strong> then« <strong>Databricks Azure</strong> ».

Fill in the information in your « <em>workspace »</em>. Select your resource group and select region « <strong>EAST US 2</strong> » in "<strong>Location</strong>" field.

Click on "<strong>Create</strong>".

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz30.png" />

After you create your Databricks workspace, your resource group should contain the following resources:

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz31.png" />
<h2>Provisioning a cluster and start analyzing your data</h2>
Click on your Databricks resource

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz32.png" />

In the "<strong>Overview</strong>" section, click on "<strong>Launch Workspace</strong>" button.

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz33.png" />

Your Azure infrastructure is ready. You can now start your data analysis with Azure Databricks.
<h1>Part 2: Using Databricks</h1>
<h2>Workshop: Data Engineering with Databricks</h2>
<h3>Create the cluster</h3>
In the Databricks workspace, on the left, click on "<strong>Clusters</strong>", and then "<strong>Create Cluster</strong>"

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz34.png" />

Here are the parameters you need to set for your cluster:
<ul>
 	<li>Databricks Runtime Version: 4</li>
 	<li>Python Version: 3</li>
 	<li>Worker Type: STANDARD_DS13_V2</li>
 	<li>Spark Config: spark.hadoop.fs.azure.account.key.<span style="background-color: yellow">&lt;yourStorageAccount&gt;</span>.blob.core.windows.net <span style="background-color: yellow">&lt;yourKey&gt;</span></li>
</ul>
Below is the sample configuration for this Workshop<strong>. </strong>

<img align="left" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz35.png" /><img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz36.png" />

Click on "<strong>Create cluster</strong>"

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz37.png" />

After a few minutes, your cluster is ready

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz38.png" />
<h3>Notebooks</h3>
On the left side of the screen, click on "<strong>Workspace</strong>" then "<strong>Users</strong>".

To the right of your alias, click the arrow and then "<strong>Import</strong>"

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz39.png" />

In the Window "<strong>Import Notebooks</strong>", click on "<strong>Url</strong>" then copy the address below

<a href="https://franmerstorage.blob.core.windows.net/databricks/Notebooks/nyc-taxi-workshop.dbc">Https://franmerstorage.blob.core.windows.net/databricks/Notebooks/nyc-taxi-workshop.dbc</a>

Click on the « <strong>Import</strong> » button

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz40.png" />

Notebooks must appear in your workspace.

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz41.png" />
<h3>Attach notebook to a cluster</h3>
Before you can start using any notebook, you need to attach it to a cluster.

Click on "<strong>Detached"</strong> and then select a cluster.
<h3>Configure your Notebook</h3>
In some Notebooks, think to replace value with your storage account information:

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz43.png" />

In the Notebook "<strong>2-CreateDatabaseObjects</strong>", fill in the fields for your Azure SQL server, SQL database and SQL Server credentials.

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz44.png" />

In this example, we will have:

<img align="left" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz45.png" /><img align="left" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz46.png" /><img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz47.png" /><span style="font-size: 14pt"><strong>
</strong></span>

Click on the Notebook « <strong>1-LoadReferenceData</strong> » to continue the workshop with Databricks

During the workshops, to return to your workspace to change working notebooks, click "<strong>Workspace</strong>" to the left of the screen.

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz48.png" />

<strong><span style="background-color: yellow">From now, continue the workshop with the notebooks. Below are tips that can be useful for the different notebooks in this workshop.</span>
</strong>
<h3>Tips with Notebooks</h3>
Some jobs will take several minutes. You can check progress by clicking on the arrows to the left of the jobs.

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz49.png" />

In the part "<strong>05-GenerateReports</strong>", in the Notebook "<strong>Report-1",</strong> you will find reports.

On the upper right of cell, click the graphic icon.

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz50.png" />

On the contextual menu, click "<strong>Show Code</strong>"

The script behind the report is displayed, like you can see below:

Under the graph, many options are available to change the visualization of your data

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz53.png" />

In the part "<strong>06-BatchJob</strong>", in the Notebook "<strong>GlobalVarsMetHods"</strong>, don't forget to fill in the values of your SQL Azure base.

First part:

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz54.png" />

Second part:
<h2>Interactive report with Power BI Desktop</h2>
After doing the latest notebook from the workshop, it can be interesting to connect Power BI Desktop to your Databricks storage .

From <a href="https://www.microsoft.com/en-us/download/details.aspx?id=45331">Power BI Desktop</a>, click « <strong>Get Data</strong> » then « <strong>More</strong> »

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz56.png" />

Select the "<strong>Spark</strong>" connector and click "<strong>Connect</strong>"

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz57.png" />

The <strong>Spark</strong> window appears. You need to provide the connection information

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz58.png" />

Right now, the Databricks cluster address is not trivial to find. But here's how to do it.

From your Databricks workspace, click "<strong>Clusters</strong>", and then the name of your cluster ("<strong>DatavoreCluster" </strong>in our example)

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz59.png" />

From the Databricks workspace, click on "<strong>Clusters</strong>" and click on " <strong>JDBC/ODBC</strong> ».

In the « <strong>JDBC URL</strong> » field, compose the server address with the 2 elements surrounded in red, and add <strong><em>Https </em></strong>to create a valid http address.

For our example this will give:

<em>https://eastus2.azuredatabricks.net:443/sql/protocolv1/o/1174394268694420/0317-035245-abed504</em>

Here's what it gives in Power BI Desktop. Click on "<strong>Ok</strong>".

Now you need the permissions .

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz62.png" />

It is necessary to generate an access token.

In the Databricks workspace, click the top right on the user icon, and then click "<strong>User settings</strong>"

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz63.png" />

Click on "<strong>Generate New Token</strong>"

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz64.png" />

Give your token an explicit name and click on "<strong>Generate</strong>"

From the "<strong>Generate New Token</strong>" window, copy and <span style="color: red"><strong>Keep</strong>
</span>this token, because it won't longer be possible to recover it later.

Click on "<strong>Done</strong>".

The token is generated!

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz67.png" />

<strong>From Power BI Desktop</strong>, copy the token in the field " <strong>Password</strong> ", and then use <em>token</em> in the field "<strong>User Name"</strong> (It's not something that can be made up, isn't it ?).

Click on "<strong>Connect</strong>".

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz68.png" />

Now, you are ready to explore your data. Select the 7 tables below, then click "<strong>Load</strong>"

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz69.png" />

Once connected to the data, click on the link icon on the left side.

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz70.png" />

By a simple drag and drop, build the connections between tables.

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz71.png" />

The "Create relationship" window appears, click on "<strong>Ok</strong>"

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz72.png" />

After you have done all the links, here is an example of what you can get:

Here is an example of a report

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1658_MicrosoftAz74.png" />
<h1>Index</h1>
In the case you want to load all the data in your storage account, it is possible to do this with the following command:

<span style="color: #0101fd;font-family: Consolas;font-size: 10pt">azcopy</span>
<span style="color: #007d9a">--source</span> https://franmerstore.blob.core.windows.net/nyctaxi-staging/ <span style="color: #007d9a">--destination</span> https://<span style="background-color: yellow">&lt;YourStorageAccount&gt;</span>.blob.core.windows.net/nyctaxi-staging/ <span style="color: #007d9a">--source-key</span> $SRC_STORAGE_ACCESS_KEY <span style="color: #007d9a">--dest-key</span> $AZURE_STORAGE_ACCESS_KEY <span style="color: #007d9a">--sync-copy --recursive</span>

In our example this command line will be:

<span style="color: #0101fd;font-family: Consolas;font-size: 10pt">azcopy</span>
<span style="color: #007d9a">--source</span> https://franmerstore.blob.core.windows.net/nyctaxi-staging/ <span style="color: #007d9a">--destination</span> https://datavorestorage.blob.core.windows.net/nyctaxi-staging/ <span style="color: #007d9a">--source-key</span> $SRC_STORAGE_ACCESS_KEY <span style="color: #007d9a">--dest-key</span> $AZURE_STORAGE_ACCESS_KEY <span style="color: #007d9a">--sync-copy –recursive</span>]]></content:encoded>
    </item>
    <item>
      <title>Microsoft Azure Databricks</title>
      <link>https://docs.microsoft.com/archive/blogs/franmer/11195</link>
      <pubDate>Mon, 09 Apr 2018 16:12:28 GMT</pubDate>
      <dc:creator><![CDATA[Franck Mercier]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/franmer/?p=11195</guid>
      <description><![CDATA[Lors de l'évènement Datavore 2018 à Montréal, j'ai participé à l'animation d'un atelier sur Azure...]]></description>
      <content:encoded><![CDATA[<span style="color: #333333;font-family: Georgia">Lors de l'évènement Datavore 2018 à Montréal, j'ai participé à l'animation d'un atelier sur Azure Databricks. Cet article reprend les différentes étapes de l'atelier que j'ai délivré.</span>
<h2>Présentation d'Azure Databricks</h2>
Azure Databricks est une plateforme collaborative de données massives et d'apprentissage automatique, qui s'adapte automatiquement à vos besoins. Ce nouveau service Azure consiste en une plateforme d'analyse basée sur Apache Spark et optimisée pour la plateforme de services infonuagiques Azure. Azure Databricks comprend l'ensemble des technologies et des fonctionnalités libres de mise en grappe d'Apache Spark. En outre, grâce à notre nouvelle solution, vous serez en mesure de gérer facilement et en toute sécurité des charges de travail telles que l'intelligence artificielle, l'analyse prédictive ou l'analyse en temps réel.
<h2>Atelier</h2>
Cet atelier est constitué de 2 grandes parties

<strong>Partie 1</strong> : configuration de l'environnement Azure

<strong>Partie 2</strong> : utilisation de Databricks
<ul>
 	<li>Atelier : Data Engineering avec Databricks</li>
</ul>
<h1>Partie 1 : configuration de l'environnement Azure</h1>
<h2>Création d'un groupe de ressources</h2>
Un groupe de ressources est un groupement logique de vos ressources Azure afin d'en faciliter la gestion. Toutes les ressources Azure doivent appartenir à un groupe de ressources.

<span style="font-size: 14pt">Portail Azure : <a href="https://portal.azure.com">https://portal.azure.com</a>
</span>

Depuis le portail Azure, cliquez sur « <strong>Resource groups</strong> » puis sur le bouton « <strong>Add</strong> »

Renseignez les informations de votre groupe de ressources.

Pour ce laboratoire, choisissez la région « <strong>East US 2 ». </strong>Cliquez sur le bouton<strong> « Create »
</strong>

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_2.png" />

Une fois le groupe de ressources créé, une notification apparait en haut à droite de l'écran. Cliquez sur « <strong>Go to resource group</strong> ».

Votre groupe de ressources est créé et prêt à être utilisé.
<h2>Création d'un compte de stockage</h2>
Un compte de stockage Azure est un service cloud qui fournit un stockage hautement disponible, sécurisé, durable, évolutif et redondant. Le stockage Azure se compose du stockage d'objets blob, du stockage de fichiers et du stockage de files d'attente. Pour notre laboratoire, nous allons utiliser le stockage d'objets blob. Pour plus d'informations sur le stockage Azure, vous pouvez consulter cet article : <a href="https://docs.microsoft.com/fr-fr/azure/storage/">https://docs.microsoft.com/fr-fr/azure/storage/</a>

Pour comprendre un peu le concept, un compte de stockage peut contenir un ou plusieurs containeurs qui eux-mêmes vont contenir les blobs (dossiers et fichiers)

Le compte de stockage peut être crée de la même manière que le groupe de ressources, via le portail. Mais il est possible aussi d'utiliser le « <em>Cloud shell</em> » intégré au portail. C'est ce que nous allons faire ci-dessous.

En haut du portail Azure, cliquez sur l'icône « <em>Cloud shell</em> ».

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_6.png" />

Le « <em>Cloud shell</em> » va s'ouvrir en bas de l'écran. Cliquez sur « <strong>Bash (Linux</strong>) »

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_7.png" />

Si c'est la première fois que vous exécutez le « <em>Cloud shell</em> », la fenêtre suivante va apparaître. Choisissez votre abonnement Azure, puis cliquez sur « <strong>Create storage</strong> ».

Une fois paramétré, le « <em>Cloud shell</em> » est prêt à être utilisé.

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_9.png" />

La création d'un compte de stockage peut se faire avec la commande suivante :

<span style="color: #0101fd;font-family: Consolas;font-size: 10pt">az storage account </span><span style="color: #0101fd;font-family: Consolas;font-size: 10pt">create </span><span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--name </span><span style="background-color: yellow">&lt;yourStorageAccount&gt; </span><span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--resource-group </span><span style="background-color: yellow"><strong>&lt;yourResourceGroup&gt; </strong></span><span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--location</span> eastus2 <span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--sku</span> Standard_LRS

Dans le cas de cet exemple, voici la ligne de commande correspondante :

<span style="color: #0101fd;font-family: Consolas;font-size: 10pt">az storage account create </span><span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--name</span> datavorestorage <span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--resource-group</span> datavore <span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--location</span> eastus2 <span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--sku</span> Standard_LRS

Au bout de quelques secondes le compte de stockage est créé. Cliquez sur le bouton « <strong>refresh</strong> »de votre groupe de ressources. Votre compte de stockage doit alors apparaître.

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_11.png" />

Si vous cliquez sur votre compte de stockage, vous accéderez alors aux différentes fonctions et propriétés du compte de stockage. Notamment pour retrouver les informations de connexions en cliquant sur « <strong>Access Key</strong> ».

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_12.png" />

Maintenant que le compte de stockage est disponible, nous allons créer les containeurs pour y stocker nos différents fichiers.

Avant de pouvoir créer les containeurs, il faut pouvoir accéder au compte de stockage. Pour cela, il faut récupérer les clefs d'accès au compte. Ci-dessous une commande permettant de récupérer les clefs.

<span style="color: #0101fd;font-family: Consolas;font-size: 10pt">az storage account keys list </span><span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--account-name </span><span style="background-color: yellow">&lt;yourStorageAccount &gt; </span><span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--resource-group </span><span style="background-color: yellow">&lt;yourResourceGroup&gt; </span><span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--output </span><span style="color: #0101fd;font-family: Consolas;font-size: 10pt">table</span>

Dans notre exemple, voici la commande utilisée

<span style="color: #0101fd;font-family: Consolas;font-size: 10pt">az storage account keys list </span><span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--account-name</span> datavorestorage <span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--resource-group</span> datavore <span style="color: #007d9a"><span style="font-family: Consolas;font-size: 10pt">--output <span style="color: #0101fd">table</span></span>
</span>

Copiez une des 2 clefs puis exportez les informations de votre compte de stockage

<span style="color: #0101fd;font-family: Consolas;font-size: 10pt">export</span> AZURE_STORAGE_ACCOUNT="<span style="background-color: yellow">&lt;YourStorageAccount&gt;</span>"

<span style="color: #0101fd;font-family: Consolas;font-size: 10pt">export</span> AZURE_STORAGE_ACCESS_KEY="<span style="background-color: yellow">&lt;YourKey&gt;</span>"

Voici les lignes de commande concernant notre laboratoire

<span style="color: #0101fd;font-family: Consolas;font-size: 10pt">export</span> AZURE_STORAGE_ACCOUNT="datavorestorage"

<span style="color: #0101fd;font-family: Consolas;font-size: 10pt">export</span> AZURE_STORAGE_ACCESS_KEY=" yqwBdGRgCW0LWdEuRwGdnxKPit+zXNrrVOxXQy57wq6oHmCSy2NnoA3Pr9E4pMgJPwcVeg8uQt1Uzk5YAWntiw=="
<h3>Création des containeurs</h3>
<span style="color: #0101fd;font-family: Consolas;font-size: 10pt">az <span style="color: black"><span style="color: #0101fd">storage <span style="color: black"><span style="color: #0101fd">container <span style="color: black"><span style="color: #0101fd">create<span style="color: #007d9a"> --name<span style="color: black"><span style="background-color: #f9f9f9"> nyctaxi-consumption
</span><span style="color: #0101fd">az <span style="color: black"><span style="color: #0101fd">storage <span style="color: black"><span style="color: #0101fd">container <span style="color: black"><span style="color: #0101fd">create<span style="color: #007d9a"> --name<span style="color: black"><span style="background-color: #f9f9f9"> nyctaxi-curated
</span><span style="color: #0101fd">az <span style="color: black"><span style="color: #0101fd">storage <span style="color: black"><span style="color: #0101fd">container <span style="color: black"><span style="color: #0101fd">create<span style="color: #007d9a"> --name<span style="color: black"><span style="background-color: #f9f9f9"> nyctaxi-demo
</span><span style="color: #0101fd">az <span style="color: black"><span style="color: #0101fd">storage <span style="color: black"><span style="color: #0101fd">container <span style="color: black"><span style="color: #0101fd">create<span style="color: #007d9a"> --name<span style="color: black"><span style="background-color: #f9f9f9"> nyctaxi-raw
</span><span style="color: #0101fd">az <span style="color: black"><span style="color: #0101fd">storage <span style="color: black"><span style="color: #0101fd">container <span style="color: black"><span style="color: #0101fd">create<span style="color: #007d9a"> --name<span style="color: black"><span style="background-color: #f9f9f9"> nyctaxi-ref-data
</span><span style="color: #0101fd">az <span style="color: black"><span style="color: #0101fd">storage <span style="color: black"><span style="color: #0101fd">container <span style="color: black"><span style="color: #0101fd">create<span style="color: #007d9a"> --name<span style="color: black"><span style="background-color: #f9f9f9"> nyctaxi-staging
</span><span style="color: #0101fd">az <span style="color: black"><span style="color: #0101fd">storage <span style="color: black"><span style="color: #0101fd">container <span style="color: black"><span style="color: #0101fd">create<span style="color: #007d9a"> --name<span style="color: black;background-color: #f9f9f9"> nyctaxi-scratch
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_14.png" />

Pour vérifier la création de vos containers, depuis le portail Azure, cliquez sur votre stockage Azure

Dans la vue « <strong>Overview</strong> », cliquez sur « <strong>Blobs</strong> »

Vous devez retrouver les containeurs créés précédemment

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_17.png" />
<h2>Copie des fichiers pour le laboratoire</h2>
<h3>Données de références</h3>
Les fichiers sont stockés sur un de nos comptes de stockage. <strong><span style="color: red">Ne modifiez surtout pas la clef ci-dessous</span>.</strong>

Exécutez ce script dans le « <em>Cloud Shell</em> »

<span style="color: #0101fd;font-family: Consolas;font-size: 10pt">export <span style="color: black;background-color: #f9f9f9">SRC_STORAGE_ACCOUNT="franmerstore"
</span></span>

<span style="color: #0101fd;font-family: Consolas;font-size: 10pt">export <span style="color: black;background-color: #f9f9f9">SRC_STORAGE_ACCESS_KEY="<span style="color: red">eSSFOUVLg4gB3iSxuFVh/lDVoMeQHCqVj67xHdaYcPYoMSUqFuD+E2OeDhY4wRZCEF97nCRGOV0i7WJDyoOd7g==<span style="color: black">"
</span></span></span></span>

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_18.png" />

Puis la commande suivante :

<span style="color: #0101fd"><span style="font-family: Consolas;font-size: 10pt">azcopy <span style="color: #007d9a">--source</span></span> https://</span>franmerstore.blob.core.windows.net/nyctaxi-staging/reference-data/ <span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--destination</span> https://<span style="background-color: yellow"> &lt;YourStorageAccount&gt;</span>.blob.core.windows.net/nyctaxi-staging/reference-data/ <span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--source-key </span>$SRC_STORAGE_ACCESS_KEY <span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--dest-key</span> $AZURE_STORAGE_ACCESS_KEY <span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--sync-copy ––recursive<span style="color: #0101fd">
</span></span>

Dans notre exemple, voici la commande à exécuter avec le compte de stockage utilisé dans cet exemple :

<span style="color: #0101fd"><span style="font-family: Consolas;font-size: 10pt">azcopy <span style="color: #007d9a">--source</span></span> https://</span>franmerstore.blob.core.windows.net/nyctaxi-staging/reference-data/ <span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--destination</span> https://datavorestorage.blob.core.windows.net/nyctaxi-staging/reference-data/ <span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--source-key </span>$SRC_STORAGE_ACCESS_KEY <span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--dest-key</span> $AZURE_STORAGE_ACCESS_KEY <span style="color: #007d9a;font-family: Consolas;font-size: 10pt">--sync-copy --recursive
</span>

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_19.png" />
<h3>Copie des données transactionnelles</h3>
Pour ce laboratoire, nous allons prendre juste un sous-ensemble des données. Si vous souhaitez récupérer l'ensemble des données référez-vous à l'index en fin de document (cela prendra au moins 2h).

Pour ce laboratoire, nous allons travailler uniquement sur l'année 2017, mais rien ne vous empêchera par la suite de réexécuter les scripts en changeant simplement l'année

Voici les scripts pour copier les données transactionnelles :

<span style="color: #0101fd;font-family: Consolas;font-size: 10pt">azcopy</span>
<span style="color: #007d9a">--source</span> https://franmerstore.blob.core.windows.net/nyctaxi-staging/transactional-data/year=<span style="color: red">2017</span>/ <span style="color: #007d9a">--destination</span> https://<span style="background-color: yellow">&lt;YourStorageAccount&gt;</span>.blob.core.windows.net/nyctaxi-staging/transactional-data/year=<span style="color: red">2017</span>/ <span style="color: #007d9a">--source-key</span> $SRC_STORAGE_ACCESS_KEY <span style="color: #007d9a">--dest-key</span> $AZURE_STORAGE_ACCESS_KEY <span style="color: #007d9a">--sync-copy</span>
<span style="color: #007d9a">--recursive</span>

Dans notre exemple, nous aurons donc :

<span style="color: #0101fd;font-family: Consolas;font-size: 10pt">azcopy</span>
<span style="color: #007d9a">--source</span> https://franmerstore.blob.core.windows.net/nyctaxi-staging/transactional-data/year=<span style="color: red">2017</span>/ <span style="color: #007d9a">--destination</span> https://datavorestorage.blob.core.windows.net/nyctaxi-staging/transactional-data/year=<span style="color: red">2017</span>/ <span style="color: #007d9a">--source-key</span> $SRC_STORAGE_ACCESS_KEY <span style="color: #007d9a">--dest-key</span> $AZURE_STORAGE_ACCESS_KEY <span style="color: #007d9a">--sync-copy</span>
<span style="color: #007d9a">--recursive</span>

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_20.png" />

Pour vérifier les données, vous pouvez exécuter la commande suivante :

<span style="color: #0101fd;font-family: Consolas;font-size: 10pt">az storage blob list</span>
<span style="color: #007d9a">--container-name</span> nyctaxi-staging <span style="color: #007d9a">--output table</span>

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_21.png" />
<h2>Création d'une base Azure SQL Database</h2>
Depuis le portail Azure, cliquez sur « <strong>+ Create a resource</strong> », « <strong>Database</strong> » puis sur « <strong>SQL database</strong> »

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_22.png" />

Puis renseignez les valeurs pour votre base de données

Il se peut que vous soyez obligé de créer un serveur SQL.

Cliquez sur « <strong>Configure required settings </strong>», « <strong>Create a new server</strong> ».

Renseignez les informations du server SQL. <strong>Souvenez-vous bien du mot de passe !
</strong>

Cliquez sur « <strong>Select</strong> ».

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_23.png" />

Continuez à renseigner les informations de votre de base de données puis cliquez sur « <strong>Create</strong> »

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_24.png" />
<h2>Création des tables SQL</h2>
Depuis le portail Azure, cliquez sur votre base de données fraichement créée.

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_25.png" />

Cliquez sur « <strong>Query editor</strong> », puis sur « <strong>Login</strong> »

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_26.png" />

Entrez vos informations de connexion, puis cliquez sur « <strong>Ok</strong> ».

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_27.png" />
<h2>Création des tables</h2>
Depuis le portail Azure, copier le script T-SQL ci-dessous dans l'éditeur, puis cliquez sur « <strong>Run</strong> »
<p style="background: #fffffe"><span style="color: blue;font-family: Consolas;font-size: 10pt">DROP <span style="color: black"><span style="color: blue">TABLE <span style="color: black"><span style="color: blue">IF<span style="color: black"> EXISTS TRIPS_BY_YEAR;</span></span></span></span></span></span></p>
<p style="background: #fffffe"><span style="color: blue;font-family: Consolas;font-size: 10pt">CREATE </span><span style="color: blue;font-family: Consolas;font-size: 10pt"><span style="color: black"><span style="color: blue">TABLE<span style="color: black"> TRIPS_BY_YEAR (
</span></span></span></span></p>
<p style="background: #fffffe"><span style="color: black;font-family: Consolas;font-size: 10pt">TAXI_TYPE <span style="color: blue">VARCHAR<span style="color: black">(<span style="color: #09885a">10<span style="color: black">),</span></span></span></span></span></p>
<p style="background: #fffffe"><span style="color: black;font-family: Consolas;font-size: 10pt">TRIP_YEAR <span style="color: blue">INT<span style="color: black">,
</span></span></span></p>
<p style="background: #fffffe"><span style="color: black;font-family: Consolas;font-size: 10pt"><span style="color: blue"><span style="color: black"> </span></span></span></p>
<p style="background: #fffffe"><span style="color: black;font-family: Consolas;font-size: 10pt">TRIP_COUNT <span style="color: blue">BIGINT<span style="color: black">
</span></span></span></p>
<p style="background: #fffffe"><span style="color: black;font-family: Consolas;font-size: 10pt">);
</span></p>
<p style="background: #fffffe"><img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_28.png" /><span style="color: black;font-family: Consolas;font-size: 10pt">
</span></p>
<p style="background: #fffffe">Répétez l'opération pour les 2 tables suivantes</p>
<p style="background: #fffffe"><span style="color: blue;font-family: Consolas;font-size: 10pt">DROP<span style="color: #b00000"> </span><span style="color: black"><span style="color: blue">TABLE <span style="color: black"><span style="color: blue">IF<span style="color: black"> EXISTS TRIPS_BY_HOUR;
</span></span></span></span></span></span></p>
<p style="background: #fffffe"><span style="color: blue;font-family: Consolas;font-size: 10pt">CREATE <span style="color: black"><span style="color: blue">TABLE<span style="color: black"> TRIPS_BY_HOUR (
</span></span></span></span></p>
<p style="background: #fffffe"><span style="color: black;font-family: Consolas;font-size: 10pt">TAXI_TYPE <span style="color: blue">VARCHAR<span style="color: black">(<span style="color: #09885a">10<span style="color: black">),
</span></span></span></span></span></p>
<p style="background: #fffffe"><span style="color: black;font-family: Consolas;font-size: 10pt">TRIP_YEAR <span style="color: blue">INT<span style="color: black">,
</span></span></span></p>
<p style="background: #fffffe"><span style="color: black;font-family: Consolas;font-size: 10pt">TRIP_HOUR INT,
</span></p>
<p style="background: #fffffe"><span style="color: black;font-family: Consolas;font-size: 10pt">TRIP_COUNT <span style="color: blue">BIGINT<span style="color: black">
</span></span></span></p>
<p style="background: #fffffe"><span style="color: black;font-family: Consolas;font-size: 10pt">);
</span></p>
&nbsp;
<p style="background: #fffffe"><span style="color: blue;font-family: Consolas;font-size: 10pt">DROP <span style="color: black"><span style="color: blue">TABLE <span style="color: black"><span style="color: blue">IF<span style="color: black"> EXISTS BATCH_JOB_HISTORY;
</span></span></span></span></span></span></p>
<p style="background: #fffffe"><span style="color: blue;font-family: Consolas;font-size: 10pt">CREATE <span style="color: black"><span style="color: blue">TABLE<span style="color: black"> BATCH_JOB_HISTORY
</span></span></span></span></p>
<p style="background: #fffffe"><span style="color: black;font-family: Consolas;font-size: 10pt">(
</span></p>
<p style="background: #fffffe"><span style="color: black;font-family: Consolas;font-size: 10pt">batch_id <span style="color: blue">int<span style="color: black">,
</span></span></span></p>
<p style="background: #fffffe"><span style="color: black;font-family: Consolas;font-size: 10pt">batch_step_id <span style="color: blue">int<span style="color: black">,
</span></span></span></p>
<p style="background: #fffffe"><span style="color: black;font-family: Consolas;font-size: 10pt">batch_step_description <span style="color: blue">varchar<span style="color: black">(<span style="color: #09885a">50<span style="color: black">),
</span></span></span></span></span></p>
<p style="background: #fffffe"><span style="color: black;font-family: Consolas;font-size: 10pt">batch_step_status <span style="color: blue">varchar<span style="color: black">(<span style="color: #09885a">10<span style="color: black">),
</span></span></span></span></span></p>
<p style="background: #fffffe"><span style="color: black;font-family: Consolas;font-size: 10pt">batch_step_time <span style="color: blue">varchar<span style="color: black">(<span style="color: #09885a">25<span style="color: black">)
</span></span></span></span></span></p>
<p style="background: #fffffe"><span style="color: black;font-family: Consolas;font-size: 10pt">);
</span></p>
<p style="background: #fffffe"><span style="color: blue;font-family: Consolas;font-size: 10pt">ALTER <span style="color: black"><span style="color: blue">TABLE<span style="color: black"> BATCH_JOB_HISTORY
</span></span></span></span></p>
<p style="background: #fffffe"><span style="color: blue;font-family: Consolas;font-size: 10pt">ADD <span style="color: black"><span style="color: blue">CONSTRAINT<span style="color: black"> batch_step_time_def
</span></span></span></span></p>
<p style="background: #fffffe"><span style="color: blue;font-family: Consolas;font-size: 10pt">DEFAULT<span style="color: black"> CURRENT_TIMESTAMP <span style="color: blue">FOR<span style="color: black"> batch_step_time;
</span></span></span></span></p>
<p style="background: #fffffe"><span style="color: black;font-family: Consolas;font-size: 10pt">Vous devez voir vos tables depuis le portail Azure
</span></p>
<p style="background: #fffffe"><img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_29.png" /><span style="color: black;font-family: Consolas;font-size: 10pt">
</span></p>

<h2>Création d'une ressource Azure Databricks</h2>
Depuis le portail Azure, cliquez sur « <strong>+ Create a resource</strong> », « <strong>Data + Analytics</strong> » puis « <strong>Azure Databricks</strong> ».

Renseignez les informations de votre « <em>workspace »</em>. Placez le bien dans votre ressource groupe. Sélectionnez la région « <strong>East US 2</strong> ».

Cliquez sur « <strong>Create</strong> ».

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_30.png" />

Après la création de votre espace de travail Databricks, votre groupe de ressources doit contenir les ressources suivantes :

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_31.png" />
<h2>Provisionnez un cluster et commencez les analyses</h2>
Cliquez sur votre ressource Databricks

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_32.png" />

Puis sur le bouton « <strong>Launch Workspace</strong> ».

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_33.png" />

Votre infrastructure Azure est prête. Vous pouvez commencer l'analyse de vos données avec Databricks
<h1>Partie 2 : utilisation de Databricks</h1>
<h3>Atelier : Data Engineering avec Databricks</h3>
<h3>Création du cluster</h3>
Une fois dans l'espace de travail Databricks, sur la gauche, cliquez sur « <strong>Clusters</strong> », puis sur « <strong>Create Cluster</strong> »

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_34.png" />

Voici les paramètres du cluster à utiliser :
<ul>
 	<li>Databricks Runtime Version : 4</li>
 	<li>Python version : 3</li>
 	<li>Worker Type : Standard_DS13_v2</li>
 	<li>Spark Config : spark.hadoop.fs.azure.account.key.<span style="background-color: yellow">&lt;yourStorageAccount&gt;</span>.blob.core.windows.net <span style="background-color: yellow">&lt;yourKey&gt;</span></li>
</ul>
Ci-dessous l'exemple de configuration pour <strong>l'atelier 2. </strong>

<img align="left" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_35.png" /><img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_36.png" />

Cliquez sur « <strong>Create cluster</strong> »

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_37.png" />

Après quelques minutes, votre cluster est prêt

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_38.png" />
<h3>Notebooks</h3>
Sur la gauche de l'écran, cliquez sur « <strong>Workspace</strong> », puis « <strong>Users</strong> ».

A droite de votre alias, cliquez sur la flèche puis sur « <strong>Import</strong> »

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_39.png" />

Dans la fenêtre « <strong>Import Notebooks</strong> », cliquez sur « <strong>URL</strong> » puis copiez l'adresse ci-dessous

<a href="https://franmerstorage.blob.core.windows.net/databricks/Notebooks/nyc-taxi-workshop.dbc">https://franmerstorage.blob.core.windows.net/databricks/Notebooks/nyc-taxi-workshop.dbc</a>

Cliquez sur le bouton « <strong>Import</strong> »

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_40.png" />

Les notebooks doivent apparaître dans votre espace de travail.

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_41.png" />
<h3>Utiliser un notebook avec un cluster</h3>
Avant de pouvoir commencer à utiliser le notebook, il faut attacher ce dernier à un cluster.

Cliquez sur « <strong>Detached</strong> » puis sélectionnez un cluster.

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_42.png" />
<h3>Configuration des Notebooks</h3>
Pensez à renseigner votre compte de stockage

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_43.png" />

Dans le notebook « <strong>2-CreateDatabaseObjects</strong> », renseignez les champs concernant votre base de données Azure.

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_44.png" />

Dans cet exemple nous aurons donc

<img align="left" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_45.png" /><img align="left" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_46.png" /><img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_47.png" /><span style="font-size: 14pt"><strong>
</strong></span>

Cliquez sur le notebook « <strong>1-LoadReferenceData</strong> » pour continuer le laboratoire avec Databricks

Durant les ateliers, pour revenir sur votre espace de travail pour changer de notebooks, cliquez sur « <strong>Workspace</strong> » à gauche de l'écran.

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_48.png" />

<strong><span style="background-color: yellow">A partir de maintenant, continuez le laboratoire à partir des notebooks. Ci-dessous des conseils pour les différents notebooks de l'atelier.</span>
</strong>

Certains travaux vont prendre plusieurs minutes. Vous pourrez vérifier l'avancement en cliquant sut les flèches à gauche des travaux.

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_49.png" />

Dans la partie « <strong>05-GenerateReports</strong> », dans le notebook « <strong>Report-1</strong> », vous y trouverez des exemples de rapports.

Au niveau d'un des rapports, cliquez sur l'icône graphique.

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_50.png" />

Dans le menu contextuel, cliquez sur « <strong>Show Code</strong> »

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_51.png" />

Le script retournant les résultats permettant la création des graphiques s'affichent

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_52.png" />

Sous le graphique, de nombreuses options sont disponibles pour changer la visualisation de vos données

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_53.png" />

Dans la partie « <strong>06-BatchJob</strong> », dans le notebook « <strong>GlobalVarsMethods</strong> », n'oubliez pas de renseigner les valeurs de votre base Azure SQL

Commande 1

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_54.png" />

Commande 2

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_55.png" />
<h2>Rapport interactif avec Power BI Desktop</h2>
Après avoir fait le dernier notebook du laboratoire, il peut être intéressant de se connecter aux données avec Power BI Desktop.

Depuis <a href="https://www.microsoft.com/en-us/download/details.aspx?id=45331">Power BI Desktop</a>, cliquez sur « <strong>Get Data</strong> », « <strong>More</strong> »

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_56.png" />

Sélectionnez le connecteur « <strong>Spark</strong> »

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_57.png" />

La fenêtre suivante apparaît. Il faut donc fournir les informations de connexions

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_58.png" />

Pour le moment, l'adresse du cluster Databricks n'est pas triviale à trouver. Mais voici comment faire.

Depuis votre espace de travail Databricks, cliquez sur « <strong>Clusters</strong> », puis sur le nom de votre cluster (« <strong>DatavoreCluster » </strong>dans notre exemple)

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_59.png" />

Une fois dans la page de votre cluster, cliquez sur « <strong>JDBC/ODBC</strong> ».

Dans le champ « <strong>JDBC URL</strong> », composez l'adresse du server avec les 2 éléments entourés en rouge, et en ajoutant <strong><em>https</em></strong> au début.

Pour notre exemple cela va donner :

<em>https://eastus2.azuredatabricks.net:443/sql/protocolv1/o/1174394268694420/0317-035245-abed504</em>

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_60.png" />

Donc, voici ce que ça donne dans Power BI Desktop. Cliquez sur « <strong>Ok</strong> »

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_61.png" />

Maintenant, il faut les autorisations .

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_62.png" />

Pour cela, il est nécessaire de générer un jeton d'accès du côté de Databricks.

Dans l'espace de travail de Databricks, cliquez en haut à droite sur l'icône utilisateur, puis sur « <strong>User Settings</strong> »

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_63.png" />

Cliquez sur le bouton « <strong>Generate New Token</strong> »

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_64.png" />

Donner un nom explicite à votre jeton et cliquez sur le bouton « <strong>Generate</strong> »

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_65.png" />

Depuis la fenêtre qui apparaît, copiez et <strong>conservez</strong> bien ce jeton, car il ne sera plus possible de le récupérer par la suite.

Cliquez sur le bouton « <strong>Done</strong> ».

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_66.png" />

Le jeton est généré !

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_67.png" />

<strong>Du côté de Power BI Desktop</strong>, copiez le jeton dans le champ « <strong>Password</strong> », puis utiliser <em>token</em> dans le champ « <strong>User Name</strong> » (Effectivement, ça ne s'invente pas ).

Cliquez sur le bouton « <strong>Connect</strong> ».

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_68.png" />

Vous voilà prêt pour explorer vos données. Sélectionnez les tables ci-dessous, puis cliquez sur le bouton « <strong>Load</strong> »

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_69.png" />

Une fois les données connectées au rapport, cliquez sur l'icône de liaison qui se trouve sur la gauche.

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_70.png" />

Par un simple glisser-déposer, réaliser les liaisons entre les tables

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_71.png" />

La fenêtre de liaison apparaît, cliquez sur le bouton « <strong>Ok</strong> »

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_72.png" />

Après avoir effectué toutes les liaisons, voici un exemple de ce que vous pouvez obtenir :

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_73.png" />

Voici un exemple de rapport

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2018/04/040918_1601_74.png" />
<h1>Index</h1>
Dans le cas où vous souhaitez charger toutes les données dans votre compte de stockage, il est possible de le faire avec la commande suivante

<span style="color: #0101fd;font-family: Consolas;font-size: 10pt">azcopy</span>
<span style="color: #007d9a">--source</span> https://franmerstore.blob.core.windows.net/nyctaxi-staging/ <span style="color: #007d9a">--destination</span> https://<span style="background-color: yellow">&lt;YourStorageAccount&gt;</span>.blob.core.windows.net/nyctaxi-staging/ <span style="color: #007d9a">--source-key</span> $SRC_STORAGE_ACCESS_KEY <span style="color: #007d9a">--dest-key</span> $AZURE_STORAGE_ACCESS_KEY <span style="color: #007d9a">--sync-copy --recursive</span>

Dans notre exemple cette ligne de commande sera donc :

<span style="color: #0101fd;font-family: Consolas;font-size: 10pt">azcopy</span>
<span style="color: #007d9a">--source</span> https://franmerstore.blob.core.windows.net/nyctaxi-staging/ <span style="color: #007d9a">--destination</span> https://datavorestorage.blob.core.windows.net/nyctaxi-staging/ <span style="color: #007d9a">--source-key</span> $SRC_STORAGE_ACCESS_KEY <span style="color: #007d9a">--dest-key</span> $AZURE_STORAGE_ACCESS_KEY <span style="color: #007d9a">--sync-copy –recursive</span>]]></content:encoded>
    </item>
    <item>
      <title>Installer les drivers nVidia dans les VMs GPU NC (K80)</title>
      <link>https://docs.microsoft.com/archive/blogs/franmer/installer-les-drivers-nvidia-dans-les-vms-gpu-nc-k80</link>
      <pubDate>Thu, 14 Sep 2017 11:45:00 GMT</pubDate>
      <dc:creator><![CDATA[Franck Mercier]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/franmer/?p=7425</guid>
      <description><![CDATA[Il se peut, si vous souhaitez installer une VM GPU en suivant l’article...]]></description>
      <content:encoded><![CDATA[<br><p>Il se peut, si vous souhaitez installer une VM GPU en suivant l’article ci-dessous,<p><a href="https://docs.microsoft.com/en-us/azure/virtual-machines/linux/n-series-driver-setup#install-cuda-drivers-for-nc-vms">https://docs.microsoft.com/en-us/azure/virtual-machines/linux/n-series-driver-setup#install-cuda-drivers-for-nc-vms</a><p>que vous finissez par rencontrer l’erreur suivante :<p>« <strong>Unsupported kernel version</strong> »<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image0011.png"><img width="707" height="177" title="clip_image001" alt="clip_image001" src="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image001_thumb1.png" border="0"></a><p>On se retrouve donc dans la situation où la version du kernel n’est pas supportée par les drivers que l’on souhaite installer.<p>Dans cet article, je vais vous donner le pas à pas pour installer les drivers nVidia dans ce cas.<h1><br></h1><h1>Revenir sur le bon Kernel</h1><p>Après avoir <a href="https://docs.microsoft.com/en-us/azure/virtual-machines/linux/quick-create-portal">déployé une machine NC via le portail Azure</a>, faîtes une connexion ssh sur cette machine<p>Vérifiez la version du kernel avec la commande suivante :<blockquote><p>uname -r</p></blockquote><p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image172.png"><img width="610" height="282" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb155.png" border="0"></a></p><p>Ensuite exécutez la commande suivante pour vérifier les fichiers dans le répertoire boot :<blockquote><p>ls -l /boot</p></blockquote><p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image173.png"><img width="620" height="243" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb156.png" border="0"></a></p><p>On retrouve donc le fichier correspondant à la version du kernel retournée précédemment via la commande « <i>uname -r</i> ».<p>L’idée ici, est de changer le Kernel et d’utiliser celui listé en-dessous du kernel actuel. Dans notre cas c’est la version 3.10.0-514.e17.x86_64.<p>Pour ce faire, nous allons entrer la commande suivante. Le changement de Kernel se verra après le reboot :<blockquote><p>sudo grub2-set-default 1</p></blockquote><p>La commande suivante va lister les modules qui sont utilisé par le driver nvidia « nouveau »<blockquote><p>lsmod | grep nouveau</p></blockquote><p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image174.png"><img width="746" height="205" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb157.png" border="0"></a></p><p>L’idée maintenant est d’éviter le chargement de ce driver. <h2>Création du fichier « nouveau.conf» avec vi</h2><p>Dans le dossier /etc/modprobe.d, nous allons créer un fichier de configuration pour « blacklister » le driver.<p>Changement de répertoire<blockquote><p>cd /etc/modprobe.d</p></blockquote><p>Utilisation de l’éditeur de texte vi pour créer le fichier « nouveau.conf »<blockquote><p>sudo vi nouveau.conf</p></blockquote><p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image0093.png"><img width="662" height="73" title="clip_image009" alt="clip_image009" src="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image009_thumb2.png" border="0"></a></p><p>Dans vi, utilisez la lettre « i » du clavier pour passer en mode insertion<p>Puis entrez les 2 lignes suivantes<blockquote><p>blacklist nouveau<p>options nouveau modeset=0</p></blockquote><p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image175.png"><img width="292" height="461" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb158.png" border="0"></a></p><p>Pour sauvegarder le fichier, appuyez sur la touche « ESC », sur « : » puis sur « w »<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image176.png"><img width="289" height="483" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb159.png" border="0"></a><p>Pour vérifier le contenu du fichier, entrez la commande suivante :<blockquote><p>Cat nouveau.conf</p></blockquote><p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image015.png"><img width="594" height="120" title="clip_image015" alt="clip_image015" src="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image015_thumb.png" border="0"></a></p><p>Redémarrez la machine avec la commande :<blockquote><p>sudo reboot</p></blockquote><h3>Installation des drivers nvidia</h3><p>Après le redémarrage de la machine, connectez-vous et exécutez la commande suivante pour vérifier que nous utilisons bien l’ancien Kernel<blockquote><p>uname -r</p></blockquote><p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image0161.png"><img width="749" height="255" title="clip_image016" alt="clip_image016" src="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image016_thumb1.png" border="0"></a></p><p>Si on liste les modules sur le driver nouveau, on ne doit avoir aucune valeur en retour :<p>lsmod | grep nouveau<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image017.png"><img width="760" height="98" title="clip_image017" alt="clip_image017" src="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image017_thumb.png" border="0"></a><p>Maintenant que nous sommes dans l’ancien Kernel, on peut installer les versions des packages et driver nvidia correspondant à ce Kernel.<p>Récupération des packages :<p>wget <a href="ftp://fr2.rpmfind.net/linux/centos/7.3.1611/os/x86_64/Packages/kernel-headers-3.10.0-514.el7.x86_64.rpm">ftp://fr2.rpmfind.net/linux/centos/7.3.1611/os/x86_64/Packages/kernel-headers-3.10.0-514.el7.x86_64.rpm</a><p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image177.png"><img width="549" height="311" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb160.png" border="0"></a><p>wget <a href="ftp://fr2.rpmfind.net/linux/centos/7.3.1611/os/x86_64/Packages/kernel-devel-3.10.0-514.el7.x86_64.rpm">ftp://fr2.rpmfind.net/linux/centos/7.3.1611/os/x86_64/Packages/kernel-devel-3.10.0-514.el7.x86_64.rpm</a><p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image178.png"><img width="764" height="184" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb161.png" border="0"></a><p>Installation des 2 packages :<blockquote><p>sudo rpm -ihv kernel-devel-3.10.0-514.el7.x86_64.rpm</p></blockquote><p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image023.jpg"><img width="777" height="110" title="clip_image023" alt="clip_image023" src="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image023_thumb.jpg" border="0"></a></p><blockquote><p>sudo rpm -ihv kernel-headers-3.10.0-514.el7.x86_64.rpm</p></blockquote><p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image025.jpg"><img width="798" height="97" title="clip_image025" alt="clip_image025" src="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image025_thumb.jpg" border="0"></a></p><p>Une fois les packages installés, exécutez la commande suivante :<blockquote><p>sudo rpm -ivh <a href="https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm">https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm</a></p></blockquote><p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image027.jpg"><img width="803" height="103" title="clip_image027" alt="clip_image027" src="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image027_thumb.jpg" border="0"></a></p><p>Ensuite exécutez la commande suivante et validez par « y » quand nécessaire<blockquote><p>sudo yum install dkms</p></blockquote><p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image179.png"><img width="804" height="227" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb162.png" border="0"></a></p><h5>Installation du repository de nVidia</h5><blockquote><p>sudo rpm -ivh https://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/cuda-repo-rhel7-8.0.61-1.x86_64.rpm</p></blockquote><p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image031.jpg"><img width="819" height="89" title="clip_image031" alt="clip_image031" src="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image031_thumb.jpg" border="0"></a></p><h2>Installation des drivers nVidia</h2><p>Exécutez la commande suivante et validez par « y » quand nécessaire<blockquote><p>sudo yum install cuda cuda-drivers</p></blockquote><p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image180.png"><img width="820" height="205" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb163.png" border="0"></a></p><h2>Vérification de l’installation des drivers</h2><p>Afin de s’assurer de l’installation des drivers, exécutez la commande suivante :<blockquote><p>cat /proc/driver/nvidia/version </p></blockquote><p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image181.png"><img width="643" height="68" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb164.png" border="0"></a></p><p>Ensuite exécutez la commande suivante (la commande prend quelques secondes à s’exécuter) :<blockquote><p>nvidia-smi</p></blockquote><p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image182.png"><img width="638" height="310" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb165.png" border="0"></a></p><p>En espérant vous voir aux <a href="https://experiences17.microsoft.fr/">Microsoft experiences’17</a><p><a href="https://twitter.com/FranmerMS">Franck Mercier</a>]]></content:encoded>
    </item>
    <item>
      <title>Azure function : copie de fichiers CSV dans une table SQL Database</title>
      <link>https://docs.microsoft.com/archive/blogs/franmer/azure-function-copie-de-fichier-csv-dans-une-table-sql-database</link>
      <pubDate>Mon, 11 Sep 2017 17:16:20 GMT</pubDate>
      <dc:creator><![CDATA[Franck Mercier]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/franmer/?p=7096</guid>
      <description><![CDATA[Dans cet article, nous allons voir comment créer une fonction permettant de copier des fichiers CSV,...]]></description>
      <content:encoded><![CDATA[<p><br><p>Dans cet article, nous allons voir comment créer une fonction permettant de copier des fichiers CSV, qui arrivent dans un container, vers une table SQL Database. Nous allons utiliser la notion de « trigger » permettant de déclencher la fonction lorsqu’un nouveau fichier arrive dans le container. Une fois copié dans la table SQL, le fichier sera alors archivé dans un autre container.<p>Ci-dessous un schéma illustrant notre fonction :<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image115.png"><img width="712" height="756" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb99.png" border="0"></a><ol><li>Copie du fichier dans un container du blob storage</li><li>Déclenchement de la fonction à l’arrivée du fichier</li><li>Copie du fichier dans une table SQL Database</li><li>Déplacement du fichier dans un container d’archive </li></ol><h3>Prérequis</h3><ul><li>Un <a href="https://azure.microsoft.com/fr-fr/free/">abonnement Azure</a></li><li>Une base de données <a href="https://docs.microsoft.com/en-us/azure/sql-database/sql-database-get-started-portal">SQL Database</a></li><li><a href="https://storageexplorer.com/">Microsoft Azure Storage Explorer</a></li><li><a href="https://docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms">SQL Server Management Studio (SSMS)</a></li></ul><h3>Création d’Azure Function App</h3><p>Depuis le portail Azure (<a href="https://portal.azure.com/">https://portal.azure.com</a>), cliquez sur le bouton « <strong>+</strong> » en haut à gauche.<p>Puis dans « <strong>Compute</strong> », cliquez sur « <strong>Function App</strong> ».<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image116.png"><img width="471" height="648" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb100.png" border="0"></a><p>Cliquez sur « <b>Create</b> »<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image117.png"><img width="405" height="594" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb101.png" border="0"></a><p>Donnez un nom à votre groupe de ressource et choisissez votre région.<p>Pour cet exemple, nous créer un « <b>App Service plan</b> ». Le plan S1 suffit pour cet exemple.<p>(J’ai fait des tests en utilisant un « <b>Consumption Plan</b> », mais lors de fortes charges, ma fonction tombait en timeout).<p>Nous allons aussi créer un compte de stockage, mais vous pourrez en utiliser un déjà existant<p><i><strong>Optionnel</strong></i> : si vous souhaitez avoir des indicateurs de surveillances de votre fonction, activez Application Insights.<p>Cliquez sur le bouton « <b>Create</b> ».<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image0101.png"><img width="855" height="377" title="clip_image010" alt="clip_image010" src="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image010_thumb1.png" border="0"></a><p>Vous devez voir apparaître les services suivants dans votre groupe de ressources.<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image118.png"><img width="855" height="291" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb102.png" border="0"></a><h3>Paramétrage du compte de stockage</h3><p>Dans le compte de stockage que nous avons créé, nous allons maintenant créer 2 container (et une file d’attente) :<ul><li>Un container « <b>fichiers</b> », qui va recevoir les fichiers CSV pour y être traités</li><li>Un container « <b>archives</b> », dans lequel les fichiers vont être déplacés après traitement</li></ul><p>Pour la création <b>des containers</b> de nombreuses solutions sont possibles :<ul><li>Via le portail Azure</li><li>Via un outil tel que <a href="https://azure.microsoft.com/en-us/features/storage-explorer/">Microsoft Azure Storage Explorer</a></li><li>Via PowerShell (le compte de stockage <strong>existe</strong> <strong>déjà</strong>) :</li></ul><blockquote><p align="left">Login-AzureRMAccount<p align="left">$SubscriptionName = "Compte de démos"<p align="left">$ResourceGroupName = "Superfunkycalifragisexy"<p align="left">$StorageAccountName = "funky69storageaccount"<p align="left">$StorageContainerName = "fichiers archives"<p align="left">$Keys = Get-AzureRmStorageAccountKey -ResourceGroupName $ResourceGroupName -Name $StorageAccountName;<p align="left">$StorageContext = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $Keys[0].Value;<p align="left">Select-AzureRmSubscription -SubscriptionName $SubscriptionName<p align="left">Get-AzureRmStorageAccount -ResourceGroupName $ResourceGroupName -Name $StorageAccountName<p align="left">$StorageContainerName.split() | New-AzureStorageContainer -Permission off -Context $StorageContext</p></blockquote><p>Si on regarde dans Microsoft Azure Storage Explorer, on doit retrouver nos 2 containers :<p><a href="https://msdnshared.blob.core.windows.net/media/2017/11/image260.png"><img width="413" height="353" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/11/image_thumb238.png" border="0"></a><h3>Création d’une base SQL Database</h3><p>Depuis le portail Azure, cliquez sur le signe « <b><font size="4">+</font></b> », « <b>Databases</b> » puis « <b>SQL Database</b> »<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image120.png"><img width="801" height="579" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb104.png" border="0"></a><p>Définissez les propriétés de votre base SQL Database. <ul><li>Sélectionnez le groupe de ressources que vous avez créez au début de ce lab. Dans cet exemple, choisissez : «<b><a href="https://ms.portal.azure.com/">Superfunkycalifragisexy</a></b> »</li><li>Vous pouvez utiliser un serveur existant pour héberger votre base de données ou en créer un nouveau. Pour cet exemple, nous allons créer un nouveau serveur.</li><li>Dans la partie « <b>Pricing tier</b> », choisissez au minimum « <b>Standard S0</b> »</li></ul><p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image024.jpg"><img width="784" height="573" title="clip_image024" alt="clip_image024" src="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image024_thumb.jpg" border="0"></a></p><p>Après la création du serveur et de la base SQL Azure, voici ci-dessous les services Azure présents dans notre groupe de ressources :<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image121.png"><img width="787" height="435" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb105.png" border="0"></a><h4><br></h4><h4>Création de la table</h4><p>Cliquez sur votre base SQL Database<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image122.png"><img width="592" height="100" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb106.png" border="0"></a><p>Cliquez sur « <b>Tools</b> »<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image123.png"><img width="799" height="359" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb107.png" border="0"></a><p>Cliquez sur « <b>Query editor (preview)</b> », puis sur « <b>Login</b> »<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image124.png"><img width="803" height="197" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb108.png" border="0"></a><p>Entrez vos informations de connexion puis cliquez sur « <b>Ok</b> »<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image038.jpg"><img width="501" height="369" title="clip_image038" alt="clip_image038" src="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image038_thumb.jpg" border="0"></a><p>Copiez le script ci-dessous, puis cliquez sur « <b>Run</b> » :<blockquote><p>CREATE TABLE [dbo].[FranmerProducts](<p>[UniqueID] [int] IDENTITY(1,1) NOT NULL,<p>[ID] [int] NULL,<p>[Product] [nvarchar](200) NULL,<p>[NomDuFichier] [nchar](200) NULL,<p>[DateAjout] [datetime] NULL,<p>CONSTRAINT [PK_FranmerProducts] PRIMARY KEY NONCLUSTERED<p>(<p>[UniqueID] ASC<p>)<p>)</p></blockquote><p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image125.png"><img width="603" height="403" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb109.png" border="0"></a></p><p>Pour vérifier si votre table a bien été créée, exécutez la requête suivante :<blockquote><p>SELECT TABLE_NAME FROM &lt;Nom de votre base SQL&gt;.INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'</p></blockquote><p>Dans cet exemple, &lt;Nom de votre base SQL&gt; = <b>Anotherloverholenyohead</b></p><p>Sélectionnez la requête, puis cliquez sur « <b>Run</b> »<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image126.png"><img width="640" height="396" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb110.png" border="0"></a><h3>Création de la fonction Azure</h3><p>Nous allons créer une fonction Azure qui se déclenche séquentiellement quand un fichier arrive dans le containeur. Cette fonction aura pour but de réaliser la copie du fichier CSV dans une table SQL Database.<p>Une fonction est composée de plusieurs fichiers :<ul><li><b>run.csx</b> : c’est dans ce fichier que se trouvera l’essentiel de votre code</li><li><b>function.json</b> : ce fichier contient les metadata de configuration de votre fonction</li><li><b>project.json</b> : ce fichier permet l’utilisation de packages NuGet</li></ul><h4><br></h4><h4>Création de la fonction</h4><p>Revenez dans votre groupe de ressources et cliquez sur votre fonction<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image127.png"><img width="608" height="316" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb111.png" border="0"></a><p>Dans le menu de gauche, cliquer sur le signe « <b>+</b> » à droite de « <b>Functions</b> »<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image128.png"><img width="478" height="468" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb112.png" border="0"></a><p>Cliquez sur « <b>Custom function</b> »<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image129.png"><img width="577" height="544" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb113.png" border="0"></a><p>Sélectionnez “<strong>BlobTrigger C#”</strong><p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image130.png"><img width="619" height="411" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb114.png" border="0"></a><p>Puis renseignez les champs ci-dessous :<ul><li><b>Name your function</b> : donnez un nom à votre fonction</li><li><b>Path</b> : remplacez la valeur par défaut « <i>samples-workitems</i> » par le nom de votre container. Dans cet exemple c’est « <b>fichiers</b> »</li><li><b>Storage account connection</b><b> </b>: dans la liste déroulante, sélectionnez « <b>AzureWebJobStorage</b> »</li></ul><p>Cliquez sur le bouton « <b>Create</b> »<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image131.png"><img width="635" height="285" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb115.png" border="0"></a><p>La fonction vient d’être créée. Le fichier run.csx est maintenant ouvert.<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image132.png"><img width="644" height="119" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb116.png" border="0"></a><h4><br></h4><h3>Ajout d’une entrée et sortie</h3><p>En plus du trigger, nous allons maintenant rajouter une entrée et une sortie de type blob à notre fonction<h4>Paramétrage de l’<font style="font-weight: bold">entrée</font> blob</h4><p>Sur la gauche, cliquez sur « <b>Integrate</b> », « <b>+ New Input</b> » puis sur « <b>Azure Blob Storage</b> ».<p>Cliquez sur le bouton « <b>Select</b> »<p><a href="https://msdnshared.blob.core.windows.net/media/2017/11/image282.png"><img width="722" height="309" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/11/image_thumb259.png" border="0"></a><p>Définissez les paramètres de votre entrée :<ul><li>Donnez un nom à votre paramètre de sortie</li><li>Dans le champ « <b>Path</b> », entrez la valeur « <b>fichiers/{name}</b> » </li><li>Dans le champ « <b>Storage account connection</b> », sélectionnez la valeur correspondant à votre de compte de stockage. (« <b>AzureWebJobsStorage</b> » dans notre exemple)</li><li>Cliquez sur le bouton « <b>Save</b> »</li></ul><p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image134.png"><img width="721" height="464" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb118.png" border="0"></a></p><h6></h6><h4><br></h4><h4>Paramétrage de la sortie blob</h4><p>Sur la gauche, cliquez sur « <b>Integrate</b> », « <b>+ New Output</b> » puis sélectionnez « <b>Azure Blob Storage</b> »<p>Cliquez sur le bouton « <b>Select</b> »<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image135.png"><img width="733" height="399" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb119.png" border="0"></a><h4><br></h4><h4>Définissez les paramètres de <font style="font-weight: bold">sortie</font> blob</h4><ul><li>Donnez un nom à votre paramètre de sortie</li><li>Dans le champ « <b>Path</b> », remplacez « <b>outcontainer/{rand-guid}</b> » par « <b>archives/{name}</b> » </li><li>Dans le champ « <b>Storage account connection</b> », sélectionnez la valeur correspondant à votre de compte de stockage. (« <b>AzureWebJobsStorage</b> » dans notre exemple)</li><li>Cliquez sur le bouton « <b>Save</b> »</li></ul><p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image136.png"><img width="738" height="362" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb120.png" border="0"></a></p><h4><br></h4><h4>Paramétrage manuel des entrées et sorties de la fonction</h4><p>La définition des liens entre les entrées et sortie de la fonction se trouve dans le fichier « <strong>function.json</strong> ». <p>Une des manières pour avoir accès au fichier, est de cliquer sur « <b>Integrate</b> » puis « <b>Advanced editor</b> »<p><a href="https://msdnshared.blob.core.windows.net/media/2017/11/image261.png"><img width="740" height="357" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/11/image_thumb239.png" border="0"></a><p>Vous devez arriver sur la vue suivante :<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image091.jpg"><img width="444" height="543" title="clip_image091" alt="clip_image091" src="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image091_thumb.jpg" border="0"></a><p><strong>ATTENTION !</strong> Afin d’éviter par la suite d’avoir l’erreur suivante : <p>Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.CSV2SQL'. Microsoft.Azure.WebJobs.Host: Cannot bind blob to CloudBlockBlob using access Read.<p>Modifier le fichier en spécifiant pour les 2 clefs « <strong>direction</strong> » la valeur «<strong>inout</strong> ». ci-dessous le code du fichier modifié :<blockquote><p>{<p>"bindings": [<p>{<p>"name": "myBlob",<p>"type": "blobTrigger",<p>"direction": "in",<p>"path": "fichiers/{name}",<p>"connection": "AzureWebJobsStorage"<p>},<p>{<p>"type": "blob",<p>"name": "inputBlob",<p>"path": "fichiers/{name}",<p>"connection": "AzureWebJobsStorage",<p>"direction": "<b><font color="#ff0000">inout</font></b>"<p>},<p>{<p>"type": "blob",<p>"name": "outputBlob",<p>"path": "archives/{name}",<p>"connection": "AzureWebJobsStorage",<p>"direction": "<b><font color="#ff0000">inout</font></b>"<p>}<p>],<p>"disabled": false<p>}</p></blockquote><p>Cliquez sur le bouton « <b>Save</b> »<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image138.png"><img width="429" height="541" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb122.png" border="0"></a><h4><br></h4><h4>Ajout du code dans la fonction</h4><p>Cliquez sur le nom de votre fonction pour revenir dans le fichier « <strong>run.csx</strong> ». Puis collez le code ci-dessous :<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image139.png"><img width="741" height="176" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb123.png" border="0"></a><p>Remplacez les valeurs en <b><font color="#ff0000">rouge</font></b> par vos informations de connexion, puis cliquez sur le bouton « <b>Save</b> »<blockquote><p>#r "System.Data"<p>#r "System.IO.Compression.FileSystem" <p>#r "Microsoft.WindowsAzure.Storage"<p>using System; <p>using System.Data; <p>using System.Data.SqlClient;<p>using System.IO; <p>using System.IO.Compression;<p>using Microsoft.Azure;<p>using Microsoft.WindowsAzure.Storage; <p>using Microsoft.WindowsAzure.Storage.Blob;<p>public static void Run(Stream myBlob,CloudBlockBlob inputBlob, CloudBlockBlob outputBlob, string name, TraceWriter log)<p>{<p>log.Info($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");<p>DataTable sourceData = new DataTable();<p>sourceData.Columns.Add("ID");<p>sourceData.Columns.Add("Product");<p>sourceData.Columns.Add("NomDuFichier");<p>sourceData.Columns.Add("DateAjout");<p>try<p>{<p>using (var rd = new StreamReader(myBlob))<p>{<p>while (!rd.EndOfStream)<p>{<p>var splits = rd.ReadLine().Split(',');<p>sourceData.Rows.Add(splits[0], splits[1],name,DateTime.UtcNow);<p>}<p>}<p>log.Info($"Début de copie du fichier:{name} dans SQL Database avec BCP....");<p>SqlBulkCopy bcp = new SqlBulkCopy("Server=tcp:<font color="#ff0000">&lt;</font><b><font color="#ff0000">Nom de votre serveur SQL</font></b><font color="#ff0000">&gt;</font>.database.windows.net,1433;Initial Catalog=<font color="#ff0000">&lt;</font><font color="#ff0000"><b>Nom de votre base de donn</b><b>ées</b></font><font color="#ff0000">&gt;</font>;User ID=<font color="#ff0000">&lt;<b>Votre compte utilisateur</b>&gt;</font>;Password=<font color="#ff0000">&lt;<b>Mot de passe</b>&gt;</font>;Trusted_Connection=False;Encrypt=True;");<p>// Modifiez le mapping entre votre fichier et votre table SQL si besoin<p>SqlBulkCopyColumnMapping mapID = new SqlBulkCopyColumnMapping("ID", "ID");<p>bcp.ColumnMappings.Add(mapID);<p>SqlBulkCopyColumnMapping mapProduit = new SqlBulkCopyColumnMapping("Product", "Product");<p>bcp.ColumnMappings.Add(mapProduit);<p>SqlBulkCopyColumnMapping mapNomFichier = new SqlBulkCopyColumnMapping("NomDuFichier", "NomDuFichier");<p>bcp.ColumnMappings.Add(mapNomFichier);<p>SqlBulkCopyColumnMapping mapDateAjout = new SqlBulkCopyColumnMapping("DateAjout", "DateAjout");<p>bcp.ColumnMappings.Add(mapDateAjout);<p>bcp.DestinationTableName = "<b><font color="#ff0000">&lt;Nom de votre table SQL&gt;</font></b>";<p>bcp.BulkCopyTimeout = 600;<p>bcp.WriteToServer(sourceData);<p>log.Info($"Copie du fichier:{name} faite !");<p>log.Info($"Copie du fichier:{name} dans un container d'archives");<p>using (var stream = inputBlob.OpenRead())<p>{<p>outputBlob.UploadFromStream(stream);<p>}<p>log.Info($"Effacement du fichier:{name} qui vient d'être traité");<p>inputBlob.Delete();<p>}<p>catch (Exception ex)<p>{<p>log.Error(ex.Message);<p>}<p>}</p></blockquote><p>Ci-dessous, une copie d’écran de ma fonction :<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image140.png"><img width="767" height="446" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb124.png" border="0"></a><h4>Référencement des packages NuGet</h4><p>Pour que notre fonction puisse s’exécuter sans erreur, il reste à définir les packages Nugets que l’on souhaite utiliser.<p>Pour ce faire, il est nécessaire de créer un fichier « <b>project.json</b> » avec les références aux packages NuGet que l’on souhaite utiliser.<p>Sur la droite, cliquez sur le signe « <b>&lt;</b><b> </b>» pour ouvrir la fenêtre de navigation dans les fichiers<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image141.png"><img width="775" height="210" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb125.png" border="0"></a><p>La fenêtre suivante apparaît, cliquez sur le bouton « <b>+ Add</b> ». <p>Dans le champ « <b>File name</b> », entrez le nom de fichier « <b>project.json</b> »<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image142.png"><img width="535" height="537" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb126.png" border="0"></a><p>Une fois le fichier créé, copiez le script ci-dessous, puis cliquez sur le bouton « <b>Save</b> »:<blockquote><p>{ <p>"frameworks": { <p>"net46":{ <p>"dependencies": { <p>"WindowsAzure.Storage": "7.0.0",<p>"CsvHelper": "2.14.1"<p>} <p>} <p>} <p>}</p></blockquote><p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image143.png"><img width="635" height="241" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb127.png" border="0"></a></p><h4><br></h4><h4>Paramétrage du fichier host.json</h4><p>Afin de s’assurer que la fonction s’exécutera de manière séquentielle, lors de l’arrivé d’un fichier CSV dans le container, il est nécessaire de modifier le fichier « <b>host.json</b> » de notre application. Ce fichier va affecter le comportement de toutes les fonction présentes dans notre application.<p>Les paramétrages possibles sont expliqués ici : <a href="https://github.com/Azure/azure-webjobs-sdk-script/wiki/host.json">https://github.com/Azure/azure-webjobs-sdk-script/wiki/host.json</a><p>Depuis le portail Azure, cliquez sur le nom de votre application (ici, « <b>funky69</b> »), « <b>Platform Features</b> » puis « <b>App Service Editor</b> »<p><a href="https://msdnshared.blob.core.windows.net/media/2017/11/image262.png"><img width="733" height="654" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/11/image_thumb240.png" border="0"></a><p>Dans la fenêtre qui vient de s’ouvrir, cliquez sur « <b>host.json</b> »<p><a href="https://msdnshared.blob.core.windows.net/media/2017/11/image263.png"><img width="400" height="331" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/11/image_thumb241.png" border="0"></a><p>Copiez le script ci-dessous :<blockquote><p>{<p>"queues": {<p>"maxPollingInterval": 2000,<p>"visibilityTimeout" : "00:00:30",<p>"batchSize": 1,<p>"maxDequeueCount": 5,<p>"newBatchThreshold": 1<p>}<p>}</p></blockquote><p>Assurez-vous de voir apparaître le mot « <b>SAVED</b> » avant de quitter la fenêtre.<p><a href="https://msdnshared.blob.core.windows.net/media/2017/11/image264.png"><img width="641" height="246" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/11/image_thumb242.png" border="0"></a><p>Redémarrez la fonction (soit un « <b>Restart</b> », soit un « <b>Stop</b> » puis « <b>Start</b> »)<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image147.png"><img width="604" height="294" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb131.png" border="0"></a><h3>Test de la fonction</h3><p>Pour tester les fonctions je vais utiliser :<ul><li>Microsoft Azure Storage Explorer</li><li>SQL Server Management Studio (SSMS)</li><li>Les fichiers csv qui sont disponibles <a href="https://1drv.ms/f/s!Am-C-ktMH9lgg8Rl6y4RjorMxsREfg">ici</a></li></ul><h4><br></h4><h4>Test du trigger, de la copie et de l’archivage du fichier</h4><p>Connectez-vous sur votre compte de stockage avec Microsoft Azure Storage Explorer et copiez un fichier CSV dans le container « fichiers »<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image128.jpg"><img width="831" height="352" title="clip_image128" alt="clip_image128" src="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image128_thumb.jpg" border="0"></a><p>Si tout va bien, les logs de la fonction doivent afficher les messages de traitements du fichier<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image148.png"><img width="668" height="825" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb132.png" border="0"></a><p>Avec Microsoft Azure Storage Explorer, vérifiez la présence du fichier dans le dossier « <b>archives</b> »<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image149.png"><img width="669" height="209" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb133.png" border="0"></a><h4><br></h4><h4>Vérification de la copie dans SQL Database</h4><p>Précédemment nous avons vu qu’il était possible d’interagir avec notre base SQL depuis le portail Azure. Il est aussi possible d’utiliser SSMS. Connectez-vous à votre base SQL Database avec SSMS. Pour ce faire, récupérez l’adresse de votre serveur SQL depuis le portail Azure :<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image150.png"><img width="761" height="272" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb134.png" border="0"></a><p>Puis dans SSMS :<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image151.png"><img width="756" height="506" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb135.png" border="0"></a><p>Vérifiez que les données ont bien été copiées dans votre table.<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image142.jpg"><img width="757" height="270" title="clip_image142" alt="clip_image142" src="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image142_thumb.jpg" border="0"></a><h4><br></h4><h4>Pour aller plus loin</h4><p>Imaginons maintenant que l’on vous demande de pouvoir archiver vos fichiers dans des dossiers dont le nom correspond à la date du jour du traitement (comme ça, par hasard ).<p>Pour ce faire, il suffit de modifier le fichier « <strong>function.json</strong> » dans l’éditeur avancé :<p><a href="https://msdnshared.blob.core.windows.net/media/2017/11/image1511.png"><img width="764" height="225" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/11/image151_thumb.png" border="0"></a><p>Modifiez le fichier comme illustré ci-dessous (la section concernant la <strong>sortie</strong>):<blockquote><p>{<p>"type": "blob",<p>"name": "<strong>outputBlob</strong>",<p>"path": "archives/<font color="#ff0000">{datetime: yyyy-MM-dd-hh-mm}/{name}",</font><p>"connection": "franmermlstorage_STORAGE",<p>"direction": "inout"<p>}</p></blockquote><p>Cliquez sur le bouton « <b>Save</b> »<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/image153.png"><img width="663" height="617" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/09/image_thumb137.png" border="0"></a><p>Vérification :<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image151.jpg"><img width="664" height="301" title="clip_image151" alt="clip_image151" src="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image151_thumb.jpg" border="0"></a><h4><br></h4><h4>Test de montée en charge</h4><p>Pour ce test de montée en charge j’ai créé des fichiers CSV, de tailles différentes que, je vais charger en même temps dans le container avec Microsoft Azure Storage Explorer. Ces fichiers sont disponibles ici : <a href="https://1drv.ms/f/s!Am-C-ktMH9lgg8Rl6y4RjorMxsREfg">https://1drv.ms/f/s!Am-C-ktMH9lgg8Rl6y4RjorMxsREfg</a><p>Du côté d’Azure Storage, les fichiers semblent être traités de manière séquentielle. Je dis ça, car j’ai plutôt l’impression qu’ils sont traités 2 par 2. J’ai bien entendu essayé de passer le paramètre "<b>newBatchThreshold</b>" du fichier « <b>host.json</b> » à 0, mais la fonction ne démarrait plus ☹ ( j’ai l’erreur : « We are not able to retrieve the runtime master key. Please try again later »).<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image153.jpg"><img width="702" height="496" title="clip_image153" alt="clip_image153" src="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image153_thumb.jpg" border="0"></a><p>J’ai regardé du côté Application Insight l’occupation de mes ressources. Le plan sélectionné semble tenir la charge même si on constate des pics de consommation au niveau du CPU.<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image155.jpg"><img width="847" height="348" title="clip_image155" alt="clip_image155" src="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image155_thumb.jpg" border="0"></a><p>Une fois l’exécution de la fonction terminée, environ 35 minutes pour ce test, je fais une vérification du côté de SQL Database. On retrouve le bon nombre de lignes pour chacun des 30 fichiers :<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image156.png"><img width="359" height="686" title="clip_image156" alt="clip_image156" src="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image156_thumb.png" border="0"></a><p>Le portail nous montre l’utilisation des DTUs de notre SQL Database, configuré ici à 20 DTUs (S1)<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image158.jpg"><img width="824" height="339" title="clip_image158" alt="clip_image158" src="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image158_thumb.jpg" border="0"></a><p>Lorsque j’ai fait les tests en utilisant un « <strong>App service plan</strong> » basé sur la consommation (<strong>comsuption plan</strong>), j’ai eu de nombreux timeout, même en paramétrant le fichier “<strong>host.json</strong>” comme dans cet article, et en passant le <a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-scale">paramètre de timeout à 10 minutes</a> (par défaut le timeout dans un plan de consommation est de 5 minutes). J’ai pu résoudre le problème en passant ma base au tier premium / premium RS 2. Soit 250 DTU. Mais je trouvais que ça faisait cher payé pour ce genre de « workload ».<p>Par conséquent, un autre facteur qui peut jouer, c’est le tier du SQL database utilisé. Dans cet article, j’ai utilisé le tier S1. Dans le cas de timeout ou de besoin de traitements plus rapides, vous pouvez augmenter le tier du SQL Database.  Ci-dessous le résultat du test avec une base en S3. Le test a duré environ 25 minutes.<p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image159.png"><img width="823" height="400" title="clip_image159" alt="clip_image159" src="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image159_thumb.png" border="0"></a><p>Par curiosité, j’ai fait le test avec une base en Premium RS4 (500 DTUs), l’exécution pend moins de 5 minutes. C’est aussi ça l’intérêt du Cloud, pouvoir utiliser l’élasticité en fonction des besoins. <p><a href="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image160.png"><img width="821" height="398" title="clip_image160" alt="clip_image160" src="https://msdnshared.blob.core.windows.net/media/2017/09/clip_image160_thumb.png" border="0"></a><p>Voici donc pour une utilisation, en mode « serverless », d’un code C# permettant la copie de fichier CSV vers une base SQL Database.<p>Les fichiers de la fonction se trouvent sur mon OneDrive : <a href="https://1drv.ms/f/s!Am-C-ktMH9lgg8dJjyVZ-qTw7xoAIQ">https://1drv.ms/f/s!Am-C-ktMH9lgg8dJjyVZ-qTw7xoAIQ</a><p>En espérant vous voir aux <a href="https://experiences17.microsoft.fr/">Microsoft experiences’17</a><p><a href="https://twitter.com/FranmerMS">Franck Mercier</a>]]></content:encoded>
    </item>
    <item>
      <title>Lab Azure Big Data (5 et fin) : analyses des données avec Power BI</title>
      <link>https://docs.microsoft.com/archive/blogs/franmer/lab-azure-big-data-5-et-fin-analyses-des-donnes-avec-power-bi</link>
      <pubDate>Mon, 28 Aug 2017 18:03:48 GMT</pubDate>
      <dc:creator><![CDATA[Franck Mercier]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/franmer/?p=6295</guid>
      <description><![CDATA[Dans le cadre d’un programme de “readiness” interne, j’ai participé à la création de contenu autour...]]></description>
      <content:encoded><![CDATA[<p><br></p><p>Dans le cadre d’un programme de “readiness” interne, j’ai participé à la création de contenu autour du Big Data. Comme j’ai eu de nombreuses demandes pour récupérer le contenu que j’ai créé, je me suis dit que ça pourrait peut-être intéresser d’autres personnes. Donc je partage sur mon blog <img class="wlEmoticon wlEmoticon-smile" alt="Smile" src="https://msdnshared.blob.core.windows.net/media/2017/08/wlEmoticon-smile10.png"> !<p>Ce contenu est constitué d’une série d’articles qui va de la création d’un cluster HDInsight à l’exploitation des données.<p>Sommaire des articles<ol><li><a href="https://blogs.technet.microsoft.com/franmer/2017/07/27/lab-azure-big-data-1-cration-dun-cluster-hdinsight/">Création d’un cluster HDInsight</a><li><a href="https://blogs.technet.microsoft.com/franmer/2017/07/28/lab-azure-big-data-2-notebook-jupyter/">Utilisation de MapReduce</a><li><a href="https://blogs.technet.microsoft.com/franmer/2017/08/02/lab-azure-big-data-3-utilisation-de-hive/">Utilisation de Hive</a><li><a href="https://blogs.technet.microsoft.com/franmer/2017/08/14/lab-azure-big-data-4-utilisation-de-pig/">Utilisation de Pig</a><li><strong>Analyses des données avec Power BI</strong></li></ol><h3><a name="_Toc473534725">Pré-requis</a></h3><p>Ce lab peut être réalisé avec Power BI Desktop ou les Add-ins Power BI pour Excel 2016. Nous allons utiliser <b>Power BI Desktop</b> qui peut être téléchargé <a href="https://powerbi.microsoft.com/fr-fr/desktop/">ici</a><h3><a name="_Toc473534726">Connexion aux données</a></h3><p>Depuis Power BI Desktop, cliquez sur le bouton « <b>Get Data</b> » puis « <b>More</b><b>…</b> »<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image527.png"><img width="316" height="524" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb421.png" border="0"></a><p>Power BI Desktop propose un large choix de connecteurs. Pour ce lab nous allons choisir <b>Data Lake Store</b> comme source de données. <p>Cliquez sur « <b>Azure</b> » puis sur « <b>Microsoft Azure Data Lake Store (Beta)</b> ». (Vous pouvez choisir une autre source, si le fichier des logs ne trouve pas dans un <i>data lake</i>)<p>Cliquez sur le bouton « <b>Connect</b> »<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image528.png"><img width="531" height="581" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb422.png" border="0"></a><p>Dans la fenêtre de connexion, entrez l’URL de votre lac de données. <p>Cliquez sur le bouton « <b>Ok</b> » :<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image529.png"><img width="563" height="160" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb423.png" border="0"></a><p>Cliquez ensuite sur « <b>Sign in</b> » pour vous authentifier. Cliquez sur le bouton « <b>Connect</b> » :<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image530.png"><img width="568" height="197" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb424.png" border="0"></a><p>Une fois connecté au lac de données, une fenêtre d’aperçu apparaît. Cliquez sur le bouton « <b>Edit</b> » :<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image531.png"><img width="571" height="460" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb425.png" border="0"></a><p>La fenêtre d’édition de requête s’ouvre. Rechercher le fichier résultant du traitement <i>pig</i> réalisé durant le lab précédent. <p>Ce fichier à un nom de la forme « <b>part-r-</b> ». Ici, le fichier se trouve dans « <i>user/franmer/output-wikipedialogs</i> ». Pour naviguer dans les données, dans la colonne « <b>Content</b> », cliquez sur « <b>Table</b> »<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image532.png"><img width="575" height="237" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb426.png" border="0"></a><p>Ensuite cliquez sur « <b>Table</b> » correspondant à votre nom d’utilisateur :<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image533.png"><img width="583" height="161" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb427.png" border="0"></a><p>Puis sélectionnez le dossier contenant le fichier à traiter. Cliquez à nouveau sur « <b>Table</b> » :<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image534.png"><img width="596" height="61" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb428.png" border="0"></a><p>Une fois au niveau du fichier, cliquez sur « <b>Binary</b> » :<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image535.png"><img width="600" height="64" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb429.png" border="0"></a><p>Un aperçu des données est donc disponible :<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image536.png"><img width="491" height="440" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb430.png" border="0"></a><h3><a name="_Toc473534727">Nettoyage des données</a></h3><p>Power BI Desktop permet de mettre en forme rapidement les données, afin de pouvoir les exploiter dans des rapports.<p>L’idée, est de pouvoir isoler les différentes informations que l’on a au sein des colonnes. Si on regarde bien, comme information intéressante, nous avons le titre de l’article et la langue dans lequel cet article a été écrit. L’idée étant d’isoler ces informations au sein de colonnes distinctes.<p>Faîtes un clic droit sur la colonne « <b>Column1</b> ». Dans le menu contextuel sélectionnez « <b>Split Column</b> » puis « <b>By Number of Characters</b><b>…</b> »<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image537.png"><img width="784" height="498" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb431.png" border="0"></a><p>Le but étant d’isoler la langue de l’article. Nous allons donc partir de la droite sur 3 caractères. Remplissez le champ « <b>Number of caracters</b> », puis sélectionnez « <b>Once, as far right as possible</b> ». Cliquez sur le bouton « <b>Ok</b> »<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image538.png"><img width="802" height="327" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb432.png" border="0"></a><p>Ci-dessous le résultat obtenu. Une nouvelle colonne contient maintenant l’information sur la langue de l’article. <p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image539.png"><img width="610" height="433" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb433.png" border="0"></a><p>Afin de nettoyer la nouvelle colonne, faîtes un clic droit sur « <b>Column1.2</b> » puis sélectionnez « <b>Replace Values</b><b>…</b> »<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image540.png"><img width="587" height="354" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb434.png" border="0"></a><p>Remplacez la parenthèse «<strong> )</strong> » par aucune valeur dans le champ « <b>Replace with</b> ». Cliquez sur le bouton « <b>Ok</b> ».<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image541.png"><img width="596" height="231" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb435.png" border="0"></a><p>Ci-dessous, une copie d’écran du résultat <p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image542.png"><img width="606" height="280" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb436.png" border="0"></a><p>Continuez de nettoyer le jeu de données de la même manière. Au final on peut imaginer obtenir un résultat comme celui-ci-dessous. <b>Pensez </b><b>à renommer les colonnes</b> pour une meilleure utilisation des données lors de la phase de création de rapport.<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image543.png"><img width="606" height="483" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb437.png" border="0"></a><p>Pour information, sur la droite, vous retrouvez toutes les étapes de vos transformations <p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image544.png"><img width="615" height="366" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb438.png" border="0"></a><p>Une fois les transformations terminées, cliquez sur le bouton « <b>Close and Apply</b> » :<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image545.png"><img width="628" height="228" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb439.png" border="0"></a><h3><a name="_Toc473534728">Création du rapport</a></h3><p>Afin de créer un rapport avec Power BI Desktop, assurez-vous d’être dans la partie création de rapport. Pour ce faire, cliquez sur le bouton « <b>Report</b> » à gauche de l’écran.<p>Une fois dans l’éditeur de rapport, vous avez accès, sur la droite, aux différentes visualisations et aux champs issues de la transformation de données.<p>Pour commencer à créer un rapport, il suffit, par exemple, de cliquer sur une visualisation puis de rajouter les champs que l’on désire analyser.<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image891.png"><img width="820" height="364" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image89_thumb.png" border="0"></a><p>Ci-dessous un exemple de rapport avec une visualisation de type « <b>Tree map</b> » :<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image851.png"><img width="824" height="490" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image85_thumb.png" border="0"></a><p>Afin de rendre lisible ce rapport, il peut être utile d’utiliser les filtres de type « Top N » ou « sélection ». Dans l’exemple du « Tree map », nous allons faire un top N.<p>Cliquez sur la visualisation que vous souhaitez filtrer. Sur la droite, dans la partie « <b>Filters</b> », sélectionnez le champ sur lequel vous souhaitez appliquer le filtre. Ici, nous allons sélectionner le champ « <b>Article</b> ». Dans la liste déroulante « <b>Filter Type</b> », sélectionnez « <b>Top N</b> ».<p>Renseignez les différents champs du Filtre TOP N, puis cliquez sur « <b>Apply filter</b> »<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image941.png"><img width="526" height="627" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image94_thumb.png" border="0"></a><p>Un autre type de filtre peut être utilisé dans un rapport, ce sont les « <b>slicers</b> » :<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image981.png"><img width="369" height="428" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image98_thumb.png" border="0"></a><p>De plus, les visualisations sont interactives et peuvent servir de filtre aux autres visualisations du rapport par simple clic sur un élément d’une visualisation. <p>En utilisant les différentes visualisations disponibles, essayez de créer un rapport sur les données récupérées depuis le site Wikipédia. Ci-dessous, un exemple de rapport.<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image1021.png"><img width="855" height="384" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image102_thumb.png" border="0"></a><h3><a name="_Toc473534729">Enrichissement du rapport</a></h3><p>Power BI Desktop peut être enrichi avec des visualisations développées par la communauté ou par vous-même. Ces visualisations personnalisées sont disponibles sur le site <a title="https://store.office.com/en-us/appshome.aspx?productgroup=PowerBI" href="https://store.office.com/en-us/appshome.aspx?productgroup=PowerBI">https://store.office.com/en-us/appshome.aspx?productgroup=PowerBI</a>. <p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image546.png"><img width="584" height="412" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb440.png" border="0"></a><p>Depuis ce site, vous avez la possibilité de télécharger de nouveaux composants visuels que vous pouvez intégrer à votre rapport Power BI desktop. L’intégration de nouveaux composants visuels se fait directement depuis Power BI Desktop en cliquant sur les trois petits « … » dans la partie « <b><i>Visualizations</i></b><b><i>…</i></b> »<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image547.png"><img width="428" height="377" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb441.png" border="0"></a><h3><a name="_Toc473534730">Pour aller plus loin</a></h3><p>Lors de la récupération et transformation de données, nous avons vu que toutes les étapes étaient répertoriées et accessibles sur la droite de l’écran. Cela permet de revenir sur une étape précise de la transformation pour la modifier si besoin. <p>Pour modifier une requête existante, dans l’onglet « <b>Home</b> », cliquez sur « <b>Edit Queries</b> » :<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image548.png"><img width="607" height="210" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb442.png" border="0"></a><p>Sur la droite, les étapes de transformation sont disponibles pour modification.<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image549.png"><img width="618" height="370" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb443.png" border="0"></a><p>De plus, chacune de ces étapes sont retranscrites dans le langage M. L’accès au code de transformation est possible via l’onglet « <b>View</b> », « <b>Advanced Editor</b> ».<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image550.png"><img width="627" height="168" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb444.png" border="0"></a><p>Ci-dessous un exemple du code M de notre transformation :<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image551.png"><img width="631" height="163" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb445.png" border="0"></a><p>Ci-dessous, un lien vers un article qui utilise le Code M pour invoquer un algorithme de Machine Learning durant une étape de transformation :<p><a href="https://blogs.technet.microsoft.com/franmer/2014/11/06/power-bi-power-query-machine-learning-et-des-zombies/">https://blogs.technet.microsoft.com/franmer/2014/11/06/power-bi-power-query-machine-learning-et-des-zombies/</a><p>C’était le dernier article de cette série. En espérant que cela vous ait été utile.<p><a href="https://twitter.com/FranmerMS">Franck Mercier</a>]]></content:encoded>
    </item>
    <item>
      <title>Lab Azure Big Data (4) : utilisation de Pig</title>
      <link>https://docs.microsoft.com/archive/blogs/franmer/lab-azure-big-data-4-utilisation-de-pig</link>
      <pubDate>Mon, 14 Aug 2017 09:19:46 GMT</pubDate>
      <dc:creator><![CDATA[Franck Mercier]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/franmer/?p=5825</guid>
      <description><![CDATA[Dans le cadre d’un programme de “readiness” interne, j’ai participé à la création de contenu autour...]]></description>
      <content:encoded><![CDATA[<p>Dans le cadre d’un programme de “readiness” interne, j’ai participé à la création de contenu autour du Big Data. Comme j’ai eu de nombreuses demandes pour récupérer le contenu que j’ai créé, je me suis dit que ça pourrait peut-être intéresser d’autres personnes. Donc je partage sur mon blog <img class="wlEmoticon wlEmoticon-smile" alt="Smile" src="https://msdnshared.blob.core.windows.net/media/2017/08/wlEmoticon-smile6.png"> !<p>Ce contenu est constitué d’une série d’articles qui va de la création d’un cluster HDInsight à l’exploitation des données.<p>Sommaire des articles<ol><li><a href="https://blogs.technet.microsoft.com/franmer/2017/07/27/lab-azure-big-data-1-cration-dun-cluster-hdinsight/">Création d’un cluster HDInsight</a><li><a href="https://blogs.technet.microsoft.com/franmer/2017/07/28/lab-azure-big-data-2-notebook-jupyter/">Utilisation de MapReduce</a><li><a href="https://blogs.technet.microsoft.com/franmer/2017/08/02/lab-azure-big-data-3-utilisation-de-hive/">Utilisation de Hive</a><li><strong>Utilisation de Pig</strong><li><a href="https://blogs.technet.microsoft.com/franmer/2017/08/28/lab-azure-big-data-5-et-fin-analyses-des-donnes-avec-power-bi/">Analyses des données avec Power BI</a></li></ol><p>(Cet article reprend en grande partie celui que j’ai déjà publié <a href="https://blogs.technet.microsoft.com/franmer/2014/12/04/big-data-analyses-des-logs-wikipdia-avec-hdinsight/">ici</a>, mis à jour avec le nouveau portail Azure)</p><p><br></p><h3><a name="_Toc473549917">Préparation des données</a></h3><p>Dans ce lab, nous allons faire l’analyse des logs du site Wikipedia. Ces logs sont accessibles à l’adresse suivante :<p><a href="https://dumps.wikimedia.org/other/pageviews/2017/2017-01/">https://dumps.wikimedia.org/other/pageviews/2017/2017-01/</a><p>Nous allons récupérer 2 fichiers de logs, mais il est possible d’en récupérer plus.<p>Pour récupérer les données, il est possible de faire un WGET depuis « <b>Bash on Ubuntu on Windows</b><b> </b>».<p><br><h4><a name="_Toc473549918">Création d’un répertoire de données</a></h4><p>Avec putty ou « <b>Bash on Ubuntu on Windows</b><b> </b>», connectez-vous à votre cluster (voir le <a href="https://blogs.technet.microsoft.com/franmer/2017/07/27/lab-azure-big-data-1-cration-dun-cluster-hdinsight/">lab 01_HdInsight</a>). Puis créez un répertoire avec la commande suivante :<p>hadoop fs -mkdir /example/data/wikipedialogs<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image282.png"><img width="712" height="104" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb221.png" border="0"></a><p>Côté <em>Data Lake Store</em>, le dossier est bien créé :<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image283.png"><img width="383" height="506" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb222.png" border="0"></a><p><br><h4><a name="_Toc473549919">Récupération des données Wikipedia</a></h4><p><b>ATTENTION</b><b> !!</b> Ne prenez que des fichiers commençant par « <b>pageviews</b> »<p>Dans cet exemple, nous allons prendre les 2 fichiers suivants :<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image284.png"><img width="855" height="50" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb223.png" border="0"></a><p>Nous allons donc passer les 2 commandes suivantes :<blockquote><p><i>wget https://dumps.wikimedia.org/other/pageviews/2017/2017-01/pageviews-20170127-070000.gz</i><p><i>wget https://dumps.wikimedia.org/other/pageviews/2017/2017-01/pageviews-20170127-080000.gz</i></p></blockquote><p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image285.png"><img width="855" height="171" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb224.png" border="0"></a></p><p>Les fichiers sont téléchargés dans le cluster, ce qui signifie que si nous détruisons le cluster, les fichiers seront perdus. Nous allons donc copier les fichiers du cluster vers le <em>Data Lake Store</em>. Nous allons utiliser la commande <b><i>copyFromLocal</i></b><blockquote><p><i>hadoop fs -copyFromLocal pageviews-20170127-*.gz /example/data/wikipedialogs</i></p></blockquote><p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image286.png"><img width="855" height="242" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb225.png" border="0"></a></p><i></i><p>Si maintenant on regarde du côté de <strong>Data Lake Store,</strong> nous retrouvons bien nos 2 fichiers :<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image287.png"><img width="855" height="344" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb226.png" border="0"></a><h3><br></h3><h3><a name="_Toc473549920">Traitement des données</a></h3><p>Maintenant que nous avons récupéré et sécurisé nos données, nous allons pouvoir les exploiter. Dans cet exemple, nous allons utiliser le script pig suivant. <p><b>Attention</b>, sur la première ligne, de bien pointer vers le bon répertoire et les bons fichiers.<blockquote><p><i>records = load '/<font color="#ff0000">example/data/wikipedialogs/pageviews</font>-*.gz' using PigStorage(' ') as (project:chararray, page:chararray, requests:int, size:int);</i><p><i>filtered_records = filter records by (project == 'en') or (project == 'fr');</i><p><i>records_by_page = group filtered_records by (page, project);</i><p><i>sum_pages = foreach records_by_page generate group, SUM(filtered_records.requests);</i><p><i>result = order sum_pages by $1 desc;</i><p><i>result_limit = limit result 1000;</i><p><i>store result_limit into 'output-wikipedialogs';</i></p></blockquote><p>Nous allons créer un fichier dans lequel nous allons copier le script ci-dessous.<p>Dans la console, entrez la commande :<blockquote><p><i>vi script.pig </i></p></blockquote><p>Une copie d’écran ci-dessous :<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image288.png"><img width="729" height="206" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb227.png" border="0"></a><p>Vous entrez donc dans l’éditeur de texte vi (doc de « vi » <a href="https://wiki.linux-france.org/wiki/Utilisation_de_vi">ici</a>) :<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image289.png"><img width="741" height="394" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb228.png" border="0"></a><p>Pour passer en mode insertion, appuyez sur « i »<p>Collez le script dans l’éditeur de texte :<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image290.png"><img width="747" height="100" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb229.png" border="0"></a><p>Pour enregistrer le fichier, il faut passer en mode commande en cliquant sur la touche « <b>esc</b> ».<p>Pour quitter vi, utilisez la commande suivante :<p>« <b>:x</b> » puis la touche « <strong>return</strong> »<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image291.png"><img width="487" height="538" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb230.png" border="0"></a><p>Maintenant que nous avons créé un fichier avec le script, nous allons l’exécuter avec la commande :<blockquote><p><i>pig -f script.pig</i></p></blockquote><p>Le script va s’exécuter et la progression pourra être suivie depuis la console <p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image292.png"><img width="762" height="266" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb231.png" border="0"></a><h3><a name="_Toc473549921">Monitoring du script pig</a></h3><p>Pour monitorer l’exécution du script, connectez-vous sur votre cluster HDInsight depuis le portail Azure. Puis cliquez sur « <b>Yarn</b>»<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image441.png"><img width="657" height="640" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image44_thumb.png" border="0"></a><p>Dans le dashboard Yarn, sur la gauche, cliquez sur running afin de voir l’avancement d’exécution du script PIG.<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image293.png"><img width="802" height="213" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb232.png" border="0"></a><h3><a name="_Toc473549922">Analyse des données avec Power BI</a></h3><p>Les fichiers récupérés suite au traitement sont stockés dans <em>Data Lake Store</em> :<p><a href="https://msdnshared.blob.core.windows.net/media/2017/08/image294.png"><img width="480" height="546" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/2017/08/image_thumb233.png" border="0"></a><p>Pour analyser les données, nous allons utiliser Power BI Desktop. Cette activité sera détaillée dans le prochain lab.<p><a href="https://twitter.com/FranmerMS">Franck Mercier</a>]]></content:encoded>
    </item>
  </channel>
</rss>