Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package cl.uchile.tarea3;
- import com.datastax.driver.core.Cluster;
- import com.datastax.driver.core.LocalDate;
- import com.datastax.driver.core.ResultSet;
- import com.datastax.driver.core.Row;
- import com.datastax.driver.core.Session;
- import java.util.Date;
- import java.util.UUID;
- import java.util.*;
- import java.lang.*;
- import java.io.*;
- class Pair<A,B> {
- public A first;
- public B second;
- public Pair(A first, B second) {
- this.first = first;
- this.second = second;
- }
- }
- /**
- *
- * @author FelipeEsteban
- */
- public class Cassandra {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- Cluster cluster;
- Session session;
- cluster = Cluster.builder().addContactPoint("127.0.0.1").build();
- session = cluster.connect("mari");
- // double probabilidad;
- // LocalDate date;
- // ResultSet results1 = session.execute("SELECT * FROM probabilidad");
- // for (Row row : results1) {
- // probabilidad = (double)row.getLong("entrega_rut") / (double)row.getLong("total_rut");
- // date = row.getDate("date");
- // System.out.println("Date: " + date + "Probabilidad: " + probabilidad);
- // }
- //Top 10 productos ordenados!!
- ResultSet results2 = session.execute("SELECT * FROM Top10");
- ArrayList<Pair<Integer,String>> top = new ArrayList<>();
- for(Row row: results2){
- //transformo count en int para que no colapse
- int sumador = (int) row.getLong("count");
- top.add(new Pair<Integer, String>(sumador, row.getString("name")));
- //top.add(new Pair<Integer,String>(33, "MiProducto"));
- Collections.sort(top, new Comparator<Pair<Integer,String>>() {
- public int compare(Pair<Integer,String> p1, Pair<Integer,String> p2) {
- return p2.first - p1.first;
- }
- });
- int count = 0;
- //int max = 10;
- for (Pair<Integer,String> producto : top) {
- //System.out.println("Producto," + producto.second +",Cantidad," + producto.first);
- count = count +1;
- if (count == 10) {
- break;
- }
- }
- }
- cluster.close();
- }
- static final long NUM_100NS_INTERVALS_SINCE_UUID_EPOCH = 0x01b21dd213814000L;
- public static long getTimeFromUUID(UUID uuid) {
- return (uuid.timestamp() - NUM_100NS_INTERVALS_SINCE_UUID_EPOCH) / 10000;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement