Coder Social home page Coder Social logo

fdp2017's People

Contributors

alexredondosk8 avatar andcastillo avatar arangogutierrez avatar dfgonzalez88 avatar edwingamboa avatar haachicanoy avatar wilmermunoz avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

fdp2017's Issues

Esta seria la clase AttrType que utiliza la clase schema

public class AttrType {

public static final int INTEGER = 11;
public static final int FLOAT = 12;
public static final int STRING = 13;

public static final int COLNAME = 21;
public static final int FIELDNO = 22;

// --------------------------------------------------------------------------

/**

  • Private constructor (static class).
    */
    private AttrType() {}

/**

  • Gets the AttrType of the given value; i.e. not applicable for column names
  • or field numbers.
  • @throws IllegalArgumentException if obj is not an AttrType
    */
    public static int getType(Object obj) {
if (obj instanceof Integer) {
  return INTEGER;
}

if (obj instanceof Float) {
  return FLOAT;
}

if (obj instanceof String) {
  return STRING;
}

// otherwise, unknown type
throw new IllegalArgumentException("Unknown AttrType "
    + obj.getClass().getName());

} // public static int getType(Object obj)

/**

  • Returns a string representation of an AttrType.
    */
    public static String toString(int value) {
switch (value) {

  case INTEGER:
    return "INTEGER";

  case FLOAT:
    return "FLOAT";

  case STRING:
    return "STRING";

  case COLNAME:
    return "COLNAME";

  case FIELDNO:
    return "FIELDNO";

} // switch

return ("Unexpected AttrType " + value);

} // public static String toString(int value)

} // public class AttrType

Add IndexScan class

Add IndexScan class to provide the functionality of scanning available indexed tables.

Added example database

I've changed the file format a little, and I updated the README to reflect these changes, and added a database example.

Ejecución por medio de Sql en formato Json

Se realiza la actualizacion en la clase DataBase para poder ejecutar consultas en formato JSON : 02d4ed7

https://github.com/andcastillo/fdp2017/blob/merge/db/src/main/java/org/db/core/DataBase.java

Tambien realice un ejemplo que convierte unos nodos creados a JSON (para entender el formato de entrada), y posteriormente ese String en JSON es usado como consulta de entrada para probar la base de datos, actualmente funciona correctamente, otros compañeros podrían probar y notificar si algo se encuentra fallando.
Clase Main de Prueba:
https://github.com/andcastillo/fdp2017/blob/merge/db/src/test/java/org/db/TestMain.java

Actualizacion de la clase seqScan con respecto a los esquemas cargados en la clase DataBase, esto afecto Projection y RemoveRepeted, se corrigió correctamente y se actualizaron las clases de pruebas.

Crear interfaz para Operator

Interfaz que debe ser implementada por los Operadores de la BD (Selección, Proyección, Eliminacón de repetidos, etc).
Esta interfaz debe declarar funciones para aplicar el operador, especificar y establecer el tipo de operador.

Funcion de Seleccion

Funcion de seleccion

Caso :

SELECT * FROM table WHERE condition

Donde condition : columnId=value

La funcion que realiza la busqueda de la condicion es

         // Selection Scan
        String SelectionScan = "condition";
        Int Column = 2
        while (scanner.hasNext()) {
            List<String> line = parseLine(scanner.nextLine());
            String scanValue = line.get(Column);
              if ( SelectionScan.equals(scanValue) ) {
                printLine(line);
              }
        }

Su implementacion completa tomando los datos de un csv ubicado en data/example.csv con la estructura [id(int), string, Bool, Double]

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class CSVUtils {

    private static final char DEFAULT_SEPARATOR = ',';
    private static final char DEFAULT_QUOTE = '"';

    public static void main(String[] args) throws Exception {

        String csvFile = "data/example.csv";

        Scanner scanner = new Scanner(new File(csvFile));
        
         // Selection Scan
        String indexScan = "true";
        while (scanner.hasNext()) {
            List<String> line = parseLine(scanner.nextLine());
            String scanValue = line.get(2);
              if ( indexScan.equals(scanValue) ) {
                printLine(line);
              }
        }
        scanner.close();

    }

    public static List<String> parseLine(String cvsLine) {
        return parseLine(cvsLine, DEFAULT_SEPARATOR, DEFAULT_QUOTE);
    }

    public static void printLine(List<String> line) {
        System.out.println("id="+ line.get(0)+ " b= " + line.get(1) + ", c= " + line.get(2) + " , x=" + line.get(3));
    }

    public static void selectFromLine(List<String> line, int[] t) {
      String select = "";
      //
      for (int i = 0; i < t.length; i++) {
        select = select + line.get(i) + " ";
      }
      System.out.println(select);
    }

    public static List<String> parseLine(String cvsLine, char separators) {
        return parseLine(cvsLine, separators, DEFAULT_QUOTE);
    }

    public static List<String> parseLine(String cvsLine, char separators, char customQuote) {

        List<String> result = new ArrayList<>();

        //if empty, return!
        if (cvsLine == null && cvsLine.isEmpty()) {
            return result;
        }

        if (customQuote == ' ') {
            customQuote = DEFAULT_QUOTE;
        }

        if (separators == ' ') {
            separators = DEFAULT_SEPARATOR;
        }

        StringBuffer curVal = new StringBuffer();
        boolean inQuotes = false;
        boolean startCollectChar = false;
        boolean doubleQuotesInColumn = false;

        char[] chars = cvsLine.toCharArray();

        for (char ch : chars) {

            if (inQuotes) {
                startCollectChar = true;
                if (ch == customQuote) {
                    inQuotes = false;
                    doubleQuotesInColumn = false;
                } else {

                    //Fixed : allow "" in custom quote enclosed
                    if (ch == '\"') {
                        if (!doubleQuotesInColumn) {
                            curVal.append(ch);
                            doubleQuotesInColumn = true;
                        }
                    } else {
                        curVal.append(ch);
                    }

                }
            } else {
                if (ch == customQuote) {

                    inQuotes = true;

                    //Fixed : allow "" in empty quote enclosed
                    if (chars[0] != '"' && customQuote == '\"') {
                        curVal.append('"');
                    }

                    //double quotes in column will hit this!
                    if (startCollectChar) {
                        curVal.append('"');
                    }

                } else if (ch == separators) {

                    result.add(curVal.toString());

                    curVal = new StringBuffer();
                    startCollectChar = false;

                } else if (ch == '\r') {
                    //ignore LF characters
                    continue;
                } else if (ch == '\n') {
                    //the end, break!
                    break;
                } else {
                    curVal.append(ch);
                }
            }

        }

        result.add(curVal.toString());

        return result;
    }

}

Soportar indexScan cuando el metodo de indexado es Btree

Para soportar indexScan es necesario recorrer el BTree siguiendo un orden establecido, mantener el nodo acutal y ofrecer métodos que permitan realizar next() y consultar hasNext(), para esto se puede implementar la Interfaz Iterator

Carga de los esquemas de la base de datos

Se crea la clase Schema
984942c
Creo que mas adelante sera necesario modificarlo puesto que cuando se lee una fila de un bloque no se sabe el nombre de la columna puesto que dependen de su orden (Revisar).

Con la clase Schema planteada anteriormente se crea la funcion LoadSchemas para cargar los esquemas de toda la base de datos al iniciar la app
279d253

Se ponen unos ejemplos en el Main para acceder a los datos de los esquemas cargados
24711eb

En caso de que esten de acuerdo podriamos hacer un Pull requests en la rama Master confirmar.

Buscando por internet encontre este ejemplo de schema, se puede modificar para usarlo en el proyecto ?

import global.AttrType;

/**

  • Each tuple has a schema that defines the logical view of the raw bytes; it

  • describes the types, lengths, offsets, and names of a tuple's fields.
    */
    public class Schema {

    /** Minimum column width for output. */
    public static final int MIN_WIDTH = 10;

    // --------------------------------------------------------------------------

    /** Attribute types of the fields. */
    protected int[] types;

    /** Variable lengths of the fields. */
    protected int[] lengths;

    /** Relative offsets of the fields. */
    protected int[] offsets;

    /** Column names of the fields. */
    protected String[] names;

    // --------------------------------------------------------------------------
    public Schema clone() {
    Schema ret = new Schema(names.length);
    for (int i = 0; i < names.length; i++) {
    ret.types[i] = types[i];
    ret.lengths[i] = lengths[i];
    ret.offsets[i] = offsets[i];
    ret.names[i] = names[i];
    }
    return ret;
    }

    /**

    • Constructs a schema for the given number of fields.
      */
      public Schema(int fldcnt) {
      types = new int[fldcnt];
      lengths = new int[fldcnt];
      offsets = new int[fldcnt];
      names = new String[fldcnt];
      }

    /**

    • Sets the type, length, and name for the given field; this automatically

    • calculates its offset, provided that fields are set in ascending order.
      */
      public void initField(int fldno, int type, int length, String name) {

      // save the type, length, and name
      types[fldno] = type;
      lengths[fldno] = length;
      names[fldno] = name;

      // calculate the relative offset
      if (fldno > 0) {
      offsets[fldno] = offsets[fldno - 1] + lengths[fldno - 1];
      } else {
      offsets[fldno] = 0;
      }

    } // public void initField(int fldno, int type, int length, String name)

    /**

    • Copies a field from another schema.
    • @param fldno
    •        number of this field to set
      
    • @param schema
    •        contains the info to copy
      
    • @param srcno
    •        number of the field to copy
      

    */
    public void initField(int fldno, Schema schema, int srcno) {
    initField(fldno, schema.types[srcno], schema.lengths[srcno],
    schema.names[srcno]);
    }

    /**

    • Builds and returns a new schema resulting from joining two schemas.
    • @param s1
    •        the left schema
      
    • @param s2
    •        the right schema
      

    */
    public static Schema join(Schema s1, Schema s2) {

     // construct the new schema
     int s1cnt = s1.getCount();
     int s2cnt = s2.getCount();
     Schema schema = new Schema(s1cnt + s2cnt);
    
     // copy all fields from s1 and s2
     int fldno = 0;
     for (int i = 0; i < s1cnt; i++) {
     	schema.initField(fldno++, s1, i);
     }
     for (int i = 0; i < s2cnt; i++) {
     	schema.initField(fldno++, s2, i);
     }
    
     // return the resulting schema
     return schema;
    

    } // public static Schema join(Schema s1, Schema s2)

    // --------------------------------------------------------------------------

    /**

    • Gets the number of fields in the schema.
      */
      public int getCount() {
      // all arrays are same length
      return types.length;
      }

    /**

    • Gets the size of a tuple (in bytes).
      */
      public int getLength() {
      int len = 0;
      for (int i = 0; i < lengths.length; i++) {
      len += lengths[i];
      }
      return len;
      }

    /**

    • Gets the type of the given field.
      */
      public int fieldType(int fldno) {
      return types[fldno];
      }

    /**

    • Gets the length of the given field.
      */
      public int fieldLength(int fldno) {
      return lengths[fldno];
      }

    /**

    • Gets the offset of the given field.
      */
      public int fieldOffset(int fldno) {
      return offsets[fldno];
      }

    /**

    • Gets the name of the given field.
      */
      public String fieldName(int fldno) {
      return names[fldno];
      }

    /**

    • Gets the number of the field with the given name, or -1 if not found.
      */
      public int fieldNumber(String name) {
      for (int i = 0; i < names.length; i++) {
      if (names[i].equalsIgnoreCase(name)) {
      return i;
      }
      }
      return -1;
      }

    /**

    • Prints the schema (i.e. the first lines of typical query output).
      */
      public void print() {

      // print and space the column names
      int len = 0;
      for (int i = 0; i < types.length; i++) {

       // print the column name
       System.out.print(names[i]);
      
       // figure out the padding
       int collen = Math.max(names[i].length(), MIN_WIDTH);
       if (types[i] == AttrType.STRING) {
       	collen = Math.max(lengths[i], collen);
       }
       len += collen;
      
       // pad the output to the field length
       for (int j = 0; j < collen - names[i].length(); j++) {
       	System.out.print(' ');
       }
      

      } // for

      // print the line separator
      System.out.println();
      for (int i = 0; i < len; i++) {
      System.out.print('-');
      }
      System.out.println();

    } // public void print()

} // public class Schema

refactoring

Acabo de hacer un merge de las ramas activas y un refactoring de la organización del proyecto. He empaquetado todo y he creado un proyecto maven lo que facilita usar librerias. Pero veo que aquí todos son hard core.

Implement DB class

Algo crítico en este momento es tener una clase DataBase. Esta clase debe ser la encargada de cargar los datos y crear los índices. Luego debe ser la clase que debe recibir un query string y ejecutar la consulta. Ej

DataBase db = new DataBase("myDatabase"); //Por ejemplo. Eso debe cargar la base de datos que està en data/myDatabase

luego:

Object result = db.query("SELECT x, y, FROM A");

Result puede ser un string con el nombre de la tabla resultado, o un apuntador a folder que contiene la tabla resultado.

Uso de Proyección

Definición de Tabla

List<String> tablas = new ArrayList<>();
tablas.add("A");

Definición de Atributos

List<String> attr = new ArrayList<>();
attr.add("b");
attr.add("id");
attr.add("x");

Aplicar Proyección

Node node = new Node();

node.setTableInput(tablas);
node.setParameters(attr);
node.setType("Projection");

IOperator op = new Projection();
String result= op.apply(node);

Retorno

Nombre de la Tabla

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.