Skip to content

Commit

Permalink
fix: corrigido problema com o operador extern sort
Browse files Browse the repository at this point in the history
  • Loading branch information
crazynds committed Jun 20, 2023
1 parent 1214ca4 commit a93ab9c
Show file tree
Hide file tree
Showing 18 changed files with 98 additions and 289 deletions.
43 changes: 8 additions & 35 deletions afazer.txt
Original file line number Diff line number Diff line change
@@ -1,57 +1,30 @@


Tabela dinamica -> {
- Criar storage para armazenar itens dinamicos
}


Tabela de indexes -> {
- Arvore B+ para armazenamento de tabelas
- Operadores que usam indexes
- Criar indice primario que não seja a primary key
- Criar um complete table que use um indice primario e tenha tabelas de indices adicionais
}

Locks e permissões de acesso -> {
- MVCC
}


Testes de query -> {
- TPC-H https://www.tpc.org/tpch/

- Remover todos os sitema de locks que existe hoje e refazer do zero.

}


Parquet estrutura:
https://parquet.apache.org/documentation/latest/


PrestoDB:
https://prestodb.io/docs/current/#

Testar:{


- Simple Table {
- Testar desempenho atual máximo -> Testado sem valores reais
- Consistencia de dados -> OK
- Query Builder
}


- Memory Table -> RecordManager ArvoreBTree memoria{
- Testar desempenho atual comparado com simple table -> Testado sem valores reais
- Consistencia de dados -> OK
- Query Builder
}

- Double Table -Implementar{
- Testar desempenho atual comparado com simple table e memory table
- Consistencia de dados
}


- Group Operator {
- Testar se está funcionando com o min e max, etc...
}



}


Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

import engine.exceptions.DataBaseException;
import engine.file.streams.WriteByteStream;
Expand Down Expand Up @@ -42,6 +44,9 @@ public int write(long pos, byte[] data, int offset, int len) {
for(int x=0;x<len && pos+x<blockSize;x++){
buffer[(int)pos+x] = (short) data[offset+x];
}
//System.arraycopy(data,offset,buffer,(int)pos, (int)((len<blockSize-pos)?len:(blockSize-pos)));


//changes.addLast(bw);
if(pos+len>blockSize)return (int) (blockSize-pos);
else return len;
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/sgbd/query/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ public static void main(String[] args) {
Operator scan1 = new TableScan(biostats);
Operator scan2 = new TableScan(mlbplayers);

Operator cartesiano = new BlockNestedLoopJoin(scan2,scan1,(t1, t2) -> true);
Operator group = new GroupOperator(scan2,"mlbplayers","Team",List.of(
new CountAgregation()
));

Operator exec = group;

TestOperators.testOperator(cartesiano,15); // Executa select por 15 itens
TestOperators.testOperator(cartesiano,15); // Executa select por 15 itens
TestOperators.testOperator(cartesiano,15); // Executa select por 15 itens

TestOperators.testOperator(exec,15); // Executa select por 15 itens
TestOperators.testOperator(exec); // Executa select por 15 itens

//Fecha as tables, não serão mais acessadas

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/sgbd/query/Operator.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface Operator {
public Tuple next();
public boolean hasNext();
public void close();
public void clearTempFile();
public void freeResources();

public List<Table> getSources();
public Map<String,List<String>> getContentInfo();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/sgbd/query/TestOperators.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static void testOperator(Operator executor,long limit){
}
//Fecha operador
executor.close();
executor.clearTempFile();
executor.freeResources();
System.out.println("Count: "+count);
}

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/sgbd/query/agregation/CountAgregation.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ public CountAgregation(String sourceSrc, String columnSrc, String sourceDst, Str
public CountAgregation(String sourceSrc, String columnSrc) {
super(sourceSrc, columnSrc);
}
public CountAgregation(String sourceSrc) {
super(sourceSrc, "*");
}
public CountAgregation() {
super("*", "*");
}

@Override
public String getAgregationName() {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/sgbd/query/binaryop/BinaryOperator.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public void close() {
}

@Override
public void clearTempFile() {
this.left.clearTempFile();
this.right.clearTempFile();
public void freeResources() {
this.left.freeResources();
this.right.freeResources();
}

public List<Table> getSources(){
Expand Down
63 changes: 0 additions & 63 deletions src/main/java/sgbd/query/sourceop/FilterTableScan.java

This file was deleted.

78 changes: 0 additions & 78 deletions src/main/java/sgbd/query/sourceop/PKFilterTableScan.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/sgbd/query/sourceop/SourceOperator.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public List<Table> getSources(){
}

@Override
public void clearTempFile(){
public void freeResources(){

}

Expand Down
15 changes: 11 additions & 4 deletions src/main/java/sgbd/query/sourceop/TableScan.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ public TableScan(Table t,List<String> columns){

@Override
public void open() {
if(iterator==null)
if(columns!=null) {
if(iterator==null) {
if (columns != null) {
iterator = table.iterator(columns);
}else{
} else {
iterator = table.iterator();
}
}else{
iterator.restart();
}

}

Expand All @@ -55,7 +58,11 @@ public boolean hasNext() {

@Override
public void close() {
iterator=null;
}

@Override
public void freeResources() {
iterator.unlock();
}

@Override
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/sgbd/query/unaryop/ExternalSortOperator.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public void open() {


externalSortedTable.open();
operator.open();
ArrayList<RowData> inserts = new ArrayList<>();

long unique_val = 0;
Expand Down Expand Up @@ -171,13 +172,14 @@ public void close() {
}

@Override
public void clearTempFile() {
super.clearTempFile();
public void freeResources() {
super.freeResources();
if(scan!=null) {
try {
fileWriter.close();
} catch (IOException e) {
}
scan.freeResources();
externalSortedTable.close();
dataFile.delete();
String path = externalSortedTable.getHeader().get(Header.FILE_PATH);
Expand Down
Loading

0 comments on commit a93ab9c

Please sign in to comment.